This commit is contained in:
Oystein Kristoffer Tveit 2022-12-02 06:55:26 +01:00
parent d5e9ce2d39
commit 1f09c45ed8
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
3 changed files with 2550 additions and 0 deletions

49
day02/default.nix Normal file
View File

@ -0,0 +1,49 @@
{ pkgs, lib, ... }:
with lib;
let
guide = pipe (builtins.readFile ./input.txt) [
(splitString "\n")
(map (splitString " "))
(map (xs: { they = elemAt xs 0; you = elemAt xs 1; }))
];
inherentValue = x: { A = 1; B = 2; C = 3; }.${x};
comparativeValue = { they, you }: if they == you then 3 else
if (they == "A" && you == "B")
|| (they == "B" && you == "C")
|| (they == "C" && you == "A") then 6 else
0;
score = match: comparativeValue match + inherentValue match.you;
equalizeValueType = x: { X = "A"; Y = "B"; Z = "C"; }.${x};
answer1 = pipe guide [
(map (match@{ you, ... }: match // { you = equalizeValueType you; }))
(map score)
(foldr add 0)
toString
];
inherentValue2 = { they, you }: {
X = { A = 3; B = 1; C = 2; };
Y = { A = 1; B = 2; C = 3; };
Z = { A = 2; B = 3; C = 1; };
}.${you}.${they};
comparativeValue2 = x: { X = 0; Y = 3; Z = 6; }.${x};
score2 = match: comparativeValue2 match.you + inherentValue2 match;
answer2 = pipe guide [
(map score2)
(foldr add 0)
toString
];
in pkgs.writeText "answers" ''
Task1:
${answer1}
Task2:
${answer2}
''

2500
day02/input.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,7 @@
in {
packages.${system} = {
day01 = pkgs.callPackage ./day01 {};
day02 = pkgs.callPackage ./day02 {};
};
};
}