This commit is contained in:
Max Headroom 2022-12-09 14:59:09 +01:00
parent 4e0736a441
commit 89def61212
4 changed files with 1061 additions and 0 deletions

31
4/advanced.nix Normal file
View file

@ -0,0 +1,31 @@
with import ../lib;
let
input = fileContents ./input.txt;
bounding' = get1: get2: let
a1 = get1 0;
a2 = get1 1;
b1 = get2 0;
b2 = get2 1;
in
a1 <= b1 && a2 >= b1 ||
a2 >= b2 && a1 <= b2;
bounding = get1: get2: (bounding' get1 get2) || (bounding' get2 get1);
in
pipe input [
(splitStr "\n")
(map (flip pipe [
(splitStr ",")
(map (flip pipe [
(splitStr "-")
(map toInt)
elemAt
]))
(uncurry bounding)
]))
(filter id)
length
]

25
4/basic.nix Normal file
View file

@ -0,0 +1,25 @@
with import ../lib;
let
input = fileContents ./input.txt;
bounding' = get1: get2: (get1 0) <= (get2 0) && (get1 1) >= (get2 1);
bounding = get1: get2: (bounding' get1 get2) || (bounding' get2 get1);
in
pipe input [
(splitStr "\n")
(map (flip pipe [
(splitStr ",")
(map (flip pipe [
(splitStr "-")
(map toInt)
elemAt
]))
elemAt
(get: bounding (get 0) (get 1))
]))
(filter id)
length
]

1000
4/input.txt Normal file

File diff suppressed because it is too large Load diff

View file

@ -15,6 +15,11 @@ let
sum = foldl1 add; sum = foldl1 add;
uncurry = f: xs: pipe xs [
elemAt
(get: f (get 0) (get 1))
];
unpackAttrsCall = f: attrs: f attrs.a attrs.b; unpackAttrsCall = f: attrs: f attrs.a attrs.b;
}; };
in nixpkgsLib.fix aocLib in nixpkgsLib.fix aocLib