{ lib, utils, ... }: with lib; with builtins; with utils; let records = map (l: map toInt (splitWhitespace l)) (readLines ./input); getMaxDelta = l: (foldl' (prev: value: { inherit value; maxDelta = max prev.maxDelta (delta prev.value value); } ) { value = head l; maxDelta = 0; } l).maxDelta; isSafe = r: let sorted = sort lessThan r; in (r == sorted || r == (reverseList sorted)) && allUnique r && (3 >= getMaxDelta r); isSafeDampened = r: any isSafe ([ r ] ++ (map (deleteAt r) (range 0 (length r)))); in { part1 = count isSafe records; part2 = count isSafeDampened records; }