solve_day25 :: (test: bool) {
contents := read_entire_file(ifx test then "inputs/day25_test.txt" else "inputs/day25.txt");
lines := split(contents, cast(u8) #char "\n");
part1 := 0;
for lines {
f := 0;
for char_i: 0..it.count - 1 {
if it_index == 3 print("\t\t%, %, %\n", convert_to_digit(it[char_i]), pow_of_5(it.count - char_i), char_i);
f += convert_to_digit(it[char_i]) * pow_of_5(it.count - 1 - char_i);
}
print("%, %\n", it, f);
part1 += f;
}
snafu := convert_to_snafu(part1);
defer array_free(snafu);
print("Part 1: %\n", cast(string) snafu);
}
convert_to_digit :: (character: u8) -> s64 {
if character == {
case #char "0"; return 0;
case #char "1"; return 1;
case #char "2"; return 2;
case #char "-"; return -1;
case #char "="; return -2;
}
assert(false);
return -100000;
}
convert_to_snafu :: (num: s64) -> []u8 {
n := num;
out: [..]u8;
while n {
d := n % 5;
if d == {
case 0; array_add(*out, #char "0");
case 1; array_add(*out, #char "1");
case 2; array_add(*out, #char "2");
case 3;
array_add(*out, #char "=");
n += 2;
case 4;
array_add(*out, #char "-");
n += 1;
}
n /= 5;
}
reverse(out);
return out;
}
reverse :: (arr: []u8) {
for 0..(arr.count - 1) / 2 {
arr[it], arr[arr.count - 1 - it] = arr[arr.count - 1 - it], arr[it];
}
}
pow_of_5 :: (e: s64) -> s64 {
result := 1;
for 0..e - 1 {
result *= 5;
}
return result;
}