day3: Significantly improve answer

main
Tristan Daniël Maat 2021-12-06 04:47:33 +00:00
parent 1b7f5d83a0
commit 04a9814f1c
Signed by: tlater
GPG Key ID: 49670FD774E43268
1 changed files with 1 additions and 4 deletions

View File

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