From 04a9814f1c186719ae5310d38393aac32ee398f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Dani=C3=ABl=20Maat?= Date: Mon, 6 Dec 2021 04:47:33 +0000 Subject: [PATCH] day3: Significantly improve answer --- 3/diagnosticReader.hs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/3/diagnosticReader.hs b/3/diagnosticReader.hs index d819b8c..7a00dbd 100644 --- a/3/diagnosticReader.hs +++ b/3/diagnosticReader.hs @@ -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