Day 04
This commit is contained in:
parent
510a4329bd
commit
463afd538d
|
@ -0,0 +1,46 @@
|
||||||
|
{ pkgs, lib }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
sections = pipe (fileContents ./input.txt) [
|
||||||
|
(splitString "\n")
|
||||||
|
(map (splitString ","))
|
||||||
|
(map (map toElfRange))
|
||||||
|
(map (x: {
|
||||||
|
e1 = elemAt x 0;
|
||||||
|
e2 = elemAt x 1;
|
||||||
|
}))
|
||||||
|
];
|
||||||
|
|
||||||
|
toElfRange = start-end:
|
||||||
|
let splitSE = splitString "-" start-end;
|
||||||
|
in {
|
||||||
|
start = toInt (elemAt splitSE 0);
|
||||||
|
end = toInt (elemAt splitSE 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
eitherContainsTheOther = { e1, e2 }:
|
||||||
|
((e2.start <= e1.start) && (e1.end <= e2.end))
|
||||||
|
|| ((e1.start <= e2.start) && (e2.end <= e1.end));
|
||||||
|
|
||||||
|
answer1 = pipe sections [
|
||||||
|
(count eitherContainsTheOther)
|
||||||
|
toString
|
||||||
|
];
|
||||||
|
|
||||||
|
eitherOverlapsTheOther = { e1, e2 }:
|
||||||
|
e1.start <= e2.end && e2.start <= e1.end;
|
||||||
|
|
||||||
|
answer2 = pipe sections [
|
||||||
|
(count eitherOverlapsTheOther)
|
||||||
|
toString
|
||||||
|
];
|
||||||
|
|
||||||
|
in pkgs.writeText "answers" ''
|
||||||
|
Task1:
|
||||||
|
${answer1}
|
||||||
|
|
||||||
|
Task2:
|
||||||
|
${answer2}
|
||||||
|
''
|
File diff suppressed because it is too large
Load Diff
|
@ -9,6 +9,7 @@
|
||||||
day01 = pkgs.callPackage ./day01 { };
|
day01 = pkgs.callPackage ./day01 { };
|
||||||
day02 = pkgs.callPackage ./day02 { };
|
day02 = pkgs.callPackage ./day02 { };
|
||||||
day03 = pkgs.callPackage ./day03 { };
|
day03 = pkgs.callPackage ./day03 { };
|
||||||
|
day04 = pkgs.callPackage ./day04 { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue