Day 04
This commit is contained in:
parent
510a4329bd
commit
463afd538d
46
day04/default.nix
Normal file
46
day04/default.nix
Normal file
@ -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}
|
||||
''
|
1000
day04/input.txt
Normal file
1000
day04/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,9 +6,10 @@
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in {
|
||||
packages.${system} = {
|
||||
day01 = pkgs.callPackage ./day01 {};
|
||||
day02 = pkgs.callPackage ./day02 {};
|
||||
day03 = pkgs.callPackage ./day03 {};
|
||||
day01 = pkgs.callPackage ./day01 { };
|
||||
day02 = pkgs.callPackage ./day02 { };
|
||||
day03 = pkgs.callPackage ./day03 { };
|
||||
day04 = pkgs.callPackage ./day04 { };
|
||||
};
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user