fmt
This commit is contained in:
parent
bb768f9ae5
commit
315d8a4aa3
2 changed files with 15 additions and 4 deletions
|
@ -4,9 +4,20 @@ with builtins;
|
||||||
with utils;
|
with utils;
|
||||||
let
|
let
|
||||||
records = map (l: map toInt (splitWhitespace l)) (readLines ./input);
|
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;
|
getMaxDelta = l:
|
||||||
isSafe = r: let sorted = sort lessThan r; in (r == sorted || r == (reverseList sorted)) && allUnique r && (3 >= getMaxDelta r);
|
(foldl' (prev: value: {
|
||||||
isSafeDampened = r: any isSafe ([ r ] ++ (map (deleteAt r) (range 0 (length r))));
|
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 {
|
in {
|
||||||
part1 = count isSafe records;
|
part1 = count isSafe records;
|
||||||
part2 = count isSafeDampened records;
|
part2 = count isSafeDampened records;
|
||||||
|
|
Loading…
Reference in a new issue