From 1dc59c18ebbf05ba1b1083db6f9d8f83fe259fd7 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Mon, 1 Dec 2025 08:59:13 +0100 Subject: [PATCH] Solve 2025 day 1 part 1 --- 2025/day01/sample.txt | 10 ++++++++++ 2025/day01/solve.nix | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 2025/day01/sample.txt create mode 100644 2025/day01/solve.nix diff --git a/2025/day01/sample.txt b/2025/day01/sample.txt new file mode 100644 index 0000000..53287c7 --- /dev/null +++ b/2025/day01/sample.txt @@ -0,0 +1,10 @@ +L68 +L30 +R48 +L5 +R60 +L55 +L1 +L99 +R14 +L82 diff --git a/2025/day01/solve.nix b/2025/day01/solve.nix new file mode 100644 index 0000000..2a4f4b3 --- /dev/null +++ b/2025/day01/solve.nix @@ -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; +}