This commit is contained in:
Oystein Kristoffer Tveit 2022-12-04 15:04:22 +01:00
parent 510a4329bd
commit 463afd538d
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
3 changed files with 1050 additions and 3 deletions

46
day04/default.nix Normal file
View 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

File diff suppressed because it is too large Load Diff

View File

@ -9,6 +9,7 @@
day01 = pkgs.callPackage ./day01 { };
day02 = pkgs.callPackage ./day02 { };
day03 = pkgs.callPackage ./day03 { };
day04 = pkgs.callPackage ./day04 { };
};
};
}