2024: day 22 part 1

This commit is contained in:
Zack Buhman 2025-03-15 01:07:46 -05:00
parent b2476b2c9d
commit 98875076dc
9 changed files with 1994 additions and 2 deletions

1881
2024/day22/input.txt Normal file

File diff suppressed because it is too large Load Diff

15
2024/day22/input.txt.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t _binary_2024_day22_input_txt_start __asm("_binary_2024_day22_input_txt_start");
extern uint32_t _binary_2024_day22_input_txt_end __asm("_binary_2024_day22_input_txt_end");
extern uint32_t _binary_2024_day22_input_txt_size __asm("_binary_2024_day22_input_txt_size");
#ifdef __cplusplus
}
#endif

4
2024/day22/sample1.txt Normal file
View File

@ -0,0 +1,4 @@
1
10
100
2024

15
2024/day22/sample1.txt.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t _binary_2024_day22_sample1_txt_start __asm("_binary_2024_day22_sample1_txt_start");
extern uint32_t _binary_2024_day22_sample1_txt_end __asm("_binary_2024_day22_sample1_txt_end");
extern uint32_t _binary_2024_day22_sample1_txt_size __asm("_binary_2024_day22_sample1_txt_size");
#ifdef __cplusplus
}
#endif

57
2024/day22/solution.c Normal file
View File

@ -0,0 +1,57 @@
#include <stdint.h>
#include "parse.h"
#include "printf.h"
static inline unsigned int mix(unsigned int a, unsigned int b)
{
return (a ^ b) % 16777216;
}
static int random(int n)
{
n = mix(n, n * 64);
n = mix(n, n / 32);
n = mix(n, n * 2048);
return n;
}
static int random_n(int n, int m)
{
for (int i = 0; i < m; i++) {
n = random(n);
}
return n;
}
static int parse_input(const char * input, int length, int * ns)
{
const char * end = input + length;
int i = 0;
while (input < end) {
input = parse_base10(input, &ns[i]);
input = parse_skip(input, '\n');
i++;
}
return i;
}
int64_t _2024_day22_part1(const char * input, int length)
{
int ns[2048];
int ns_length = parse_input(input, length, ns);
int64_t sum = 0;
for (int i = 0; i < ns_length; i++) {
sum += (int64_t)random_n(ns[i], 2000);
}
return sum;
}
int64_t _2024_day22_part2(const char * input, int length)
{
return -1;
}

View File

@ -50,6 +50,8 @@
#include "2024/day18/input.txt.h"
#include "2024/day19/sample1.txt.h"
#include "2024/day19/input.txt.h"
#include "2024/day22/sample1.txt.h"
#include "2024/day22/input.txt.h"
static struct start_size sample[][2] = {
{
@ -196,6 +198,12 @@ static struct start_size sample[][2] = {
{ ( char *)&_binary_2024_day19_sample1_txt_start,
(uint32_t)&_binary_2024_day19_sample1_txt_size },
},
{
{ ( char *)&_binary_2024_day22_sample1_txt_start,
(uint32_t)&_binary_2024_day22_sample1_txt_size },
{ ( char *)&_binary_2024_day22_sample1_txt_start,
(uint32_t)&_binary_2024_day22_sample1_txt_size },
},
};
static struct start_size input[] = {
@ -247,4 +255,6 @@ static struct start_size input[] = {
(uint32_t)&_binary_2024_day18_input_txt_size },
{ ( char *)&_binary_2024_day19_input_txt_start,
(uint32_t)&_binary_2024_day19_input_txt_size },
{ ( char *)&_binary_2024_day22_input_txt_start,
(uint32_t)&_binary_2024_day22_input_txt_size },
};

View File

@ -38,7 +38,7 @@ bool runner_tick(struct runner_state * runner_state)
int year = solution[ix].year;
int day = solution[ix].day;
if (year != 2024 || day != 19) {
if (year != 2024 || day != 22) {
return false;
}

View File

@ -52,6 +52,8 @@ int64_t _2024_day18_part1(const char * input, int length);
int64_t _2024_day18_part2(const char * input, int length);
int64_t _2024_day19_part1(const char * input, int length);
int64_t _2024_day19_part2(const char * input, int length);
int64_t _2024_day22_part1(const char * input, int length);
int64_t _2024_day22_part2(const char * input, int length);
struct day_funcs solution[] = {
{
@ -174,4 +176,9 @@ struct day_funcs solution[] = {
{_2024_day19_part1, _2024_day19_part2},
NULL,
},
{
2024, 22,
{_2024_day22_part1, _2024_day22_part2},
NULL,
},
};

View File

@ -76,4 +76,7 @@ DAY_OBJ = \
2024/day18/solution.o \
2024/day19/sample1.txt.o \
2024/day19/input.txt.o \
2024/day19/solution.o
2024/day19/solution.o \
2024/day22/sample1.txt.o \
2024/day22/input.txt.o \
2024/day22/solution.o