feat(sterni/aoc/2022): day01 solutions

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>
This commit is contained in:
sterni 2022-12-01 17:36:50 +01:00
parent 7b87b2ccbb
commit 7e122fdcbc
4 changed files with 40 additions and 3 deletions

View file

@ -0,0 +1,7 @@
lib •Import •path"/../../lib.bqn"
input lib.ReadDec¨¨ (<"") lib.SplitOn •FLines •path"/input"
cpe +´¨ input
•Out "day 01.1: "•Fmt ´cpe
•Out "day 01.2: "•Fmt +´3cpe

View file

@ -0,0 +1,2 @@
/ a better approach is to use the downgraded list for both tasks, as demonstrated by leah2
(|/e),+/e@3#>e:(+/.'1_)'(&0=#'i)_i:0:"input"

View file

@ -1,7 +1,7 @@
{ depot, pkgs, lib, ... }:
let
inherit (pkgs.buildPackages) cbqn;
inherit (pkgs.buildPackages) cbqn ngn-k;
# input files are not checked in
meta.ci.skip = true;
@ -12,6 +12,7 @@ depot.nix.readTree.drvTargets {
name = "aoc-2022-shell";
packages = [
cbqn
ngn-k
depot.tvix.eval
];
};

View file

@ -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;
}