day3: Significantly improve answer

This commit is contained in:
Tristan Daniël Maat 2021-12-06 04:47:33 +00:00
parent 1b7f5d83a0
commit 04a9814f1c
Signed by: tlater
GPG key ID: 49670FD774E43268

View file

@ -46,10 +46,7 @@ listToBit list = foldr (\b acc -> (acc + toBit b)) 0 (enumerate (reverse list))
else 0
filterForLife :: ([Int] -> Int) -> [[Int]] -> [[Int]]
filterForLife targetFilter list = foldl (filterNext) list [0..length(head list)-1]
where
filterNext :: [[Int]] -> Int-> [[Int]]
filterNext acc i = acc `intersect` filterIndex targetFilter acc i
filterForLife targetFilter list = foldl (filterIndex targetFilter) list [0..length(head list)-1]
filterIndex :: ([Int] -> Int) -> [[Int]] -> Int -> [[Int]]
filterIndex targetFilter list index = filter ((==filterTarget) . (!! index)) list