advent-of-code/2022/day06/default.nix

32 lines
522 B
Nix
Raw Normal View History

2022-12-12 13:57:34 +01:00
{ pkgs, lib, AoCLib, ... }:
2022-12-06 08:34:47 +01:00
with lib;
let
2022-12-12 13:57:34 +01:00
inherit (AoCLib) allUnique;
2022-12-06 11:12:17 +01:00
countWithNUntil = n: pred: list: let
inner = list': count:
if pred (take n list')
2022-12-06 08:34:47 +01:00
then count
2022-12-06 11:12:17 +01:00
else inner (tail list') (count + 1);
in inner list 0;
2022-12-06 08:34:47 +01:00
2022-12-06 11:12:17 +01:00
answerN = n: pipe ./input.txt [
fileContents
stringToCharacters
2022-12-12 13:57:34 +01:00
(countWithNUntil n allUnique)
2022-12-06 09:47:16 +01:00
(add n)
2022-12-06 08:34:47 +01:00
toString
];
2022-12-06 09:47:16 +01:00
answer1 = answerN 4;
answer2 = answerN 14;
2022-12-06 08:34:47 +01:00
in pkgs.writeText "answers" ''
Task1:
${answer1}
Task2:
${answer2}
''