Advent-of-Nix-2024/day2/default.nix

16 lines
459 B
Nix
Raw Normal View History

2024-12-02 10:00:36 +01:00
{ lib, utils, ... }:
with lib;
with builtins;
with utils;
let
records = map (l: map toInt (splitWhitespace l)) (readLines ./input);
getDeltas = r: zipListsWith sub (init r) (drop 1 r);
2024-12-02 10:05:27 +01:00
isSafe = r:
let deltas = getDeltas r;
in (all (d: -3 <= d && d < 0) deltas) || (all (d: 3 >= d && d > 0) deltas);
isSafeDampened = r: any isSafe (map (deleteAt r) (listRange r));
2024-12-02 10:00:36 +01:00
in {
part1 = count isSafe records;
part2 = count isSafeDampened records;
}