Day 06 - cleanup 2

This commit is contained in:
Oystein Kristoffer Tveit 2022-12-06 11:12:17 +01:00
parent 53acf593e4
commit e07d1cefec
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146

View File

@ -3,41 +3,20 @@
with lib;
let
input = stringToCharacters (fileContents ./input.txt);
foldl'' = f: l: let
initial = take 2 l;
base = f (elemAt initial 0) (elemAt initial 1);
in foldl f base (drop 2 l);
zipLists = ls: let
minLength = foldl'' min (map length ls);
f = n: pipe ls [
(map (l: elemAt l n))
(imap0 (i: nameValuePair (toString i)))
listToAttrs
];
in genList f minLength;
zipNSelfDrop1 = n: l:
zipLists (map (i: drop i l) (range 0 (n - 1)));
countUntil = pred: l: let
innerCount = list: count:
if pred (head list)
countWithNUntil = n: pred: list: let
inner = list': count:
if pred (take n list')
then count
else innerCount (tail list) (count + 1);
in innerCount l 0;
else inner (tail list') (count + 1);
in inner list 0;
allItemsAreUnique = l: l == []
|| (!(elem (head l) (tail l))
&& allItemsAreUnique (tail l));
|| !(elem (head l) (tail l)) && allItemsAreUnique (tail l);
answerN = n: pipe input [
(zipNSelfDrop1 n)
(map attrValues)
(countUntil allItemsAreUnique)
answerN = n: pipe ./input.txt [
fileContents
stringToCharacters
(countWithNUntil n allItemsAreUnique)
(add n)
toString
];