mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Solve 2025 day 1 part 1
This commit is contained in:
10
2025/day01/sample.txt
Normal file
10
2025/day01/sample.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
L68
|
||||||
|
L30
|
||||||
|
R48
|
||||||
|
L5
|
||||||
|
R60
|
||||||
|
L55
|
||||||
|
L1
|
||||||
|
L99
|
||||||
|
R14
|
||||||
|
L82
|
||||||
31
2025/day01/solve.nix
Normal file
31
2025/day01/solve.nix
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
solve = input_file:
|
||||||
|
let
|
||||||
|
data = builtins.readFile input_file;
|
||||||
|
lines = builtins.filter (s: s != "" && builtins.isString s) (builtins.split "\n" data);
|
||||||
|
|
||||||
|
mod = a: b: a - (a / b) * b;
|
||||||
|
|
||||||
|
recurse = list: position:
|
||||||
|
let
|
||||||
|
first = builtins.head list;
|
||||||
|
# This is not guaranteed to work but it does
|
||||||
|
num_part = builtins.substring 1 999 first;
|
||||||
|
num = builtins.fromJSON num_part;
|
||||||
|
next = if (builtins.substring 0 1 first) == "R"
|
||||||
|
then
|
||||||
|
position + num
|
||||||
|
else
|
||||||
|
position - num;
|
||||||
|
|
||||||
|
new_position = mod ((mod next 100) + 100) 100;
|
||||||
|
|
||||||
|
score = if new_position == 0 then 1 else 0;
|
||||||
|
in
|
||||||
|
if list == [] then
|
||||||
|
0
|
||||||
|
else
|
||||||
|
score + (recurse (builtins.tail list) new_position);
|
||||||
|
in
|
||||||
|
recurse lines 50;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user