about summary refs log tree commit diff
path: root/users/sterni/exercises/aoc/2022/nix.nix
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2022-12-01T16·36+0100
committersterni <sternenseemann@systemli.org>2022-12-01T23·50+0000
commit7e122fdcbc266677e83290fef9766f761d99cb9e (patch)
tree12d76275e57d2569f5ae82c6c1a7084b95e4095b /users/sterni/exercises/aoc/2022/nix.nix
parent7b87b2ccbb77658617f008306828dd16459fa63a (diff)
feat(sterni/aoc/2022): day01 solutions r/5364
Bonus solution in k as I got sniped by leah2.

Change-Id: I806f5b2ac1388159a427bb239bfb1bb7aeb329d7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7490
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'users/sterni/exercises/aoc/2022/nix.nix')
-rw-r--r--users/sterni/exercises/aoc/2022/nix.nix31
1 files changed, 29 insertions, 2 deletions
diff --git a/users/sterni/exercises/aoc/2022/nix.nix b/users/sterni/exercises/aoc/2022/nix.nix
index 5bd3e36b5397..ca8bfc6e57df 100644
--- a/users/sterni/exercises/aoc/2022/nix.nix
+++ b/users/sterni/exercises/aoc/2022/nix.nix
@@ -1,3 +1,30 @@
-{ ... }:
+{ lib ? import <nixpkgs/lib> }:
 
-{ }
+let
+  chomp = lib.removeSuffix "\n";
+  lines = s: builtins.filter builtins.isString (builtins.split "\n" (chomp s));
+  sum = builtins.foldl' builtins.add 0;
+
+  day01 =
+    let
+      input =
+        builtins.map
+          (elf:
+            sum (builtins.map builtins.fromJSON (lines elf))
+          )
+          (
+            builtins.filter builtins.isString (
+              builtins.split "\n\n" (builtins.readFile ./01/input)
+            )
+          );
+    in
+    {
+      "1" = builtins.foldl' lib.max (-1) input;
+      "2" = sum (lib.sublist 0 3 (lib.sort (a: b: a >= b) input));
+    };
+
+in
+
+{
+  inherit day01;
+}