15 lines
459 B
Nix
15 lines
459 B
Nix
{ 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);
|
|
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));
|
|
in {
|
|
part1 = count isSafe records;
|
|
part2 = count isSafeDampened records;
|
|
}
|