Skip to content

Commit f8d5815

Browse files
committed
fixed off by 1 error; used wrong list for maximum retrieval
1 parent a59c138 commit f8d5815

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

10.hs

+7-5
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,17 @@ dummyAdapters2 = [ 28
4949
, 10
5050
, 3 ]
5151

52+
counts l = map (\x -> (x, length $ filter (==x) l)) [0..3]
53+
54+
calcResult l = snd . head $ scanr (\a (b,l) -> (a ,(b-a):l)) (maximum l + 3,[]) $ sort $ 0:l
55+
5256
main = do
53-
54-
let counts l = map (\x -> (x, length $ filter (==x) l)) [0..3]
55-
calcResult l = snd . head $ scanr (\a (b,l) -> (a ,(b-a):l)) (maximum dummyAdapters + 3,[]) $ sort $ 0:l
56-
dummyResult = calcResult dummyAdapters
57+
let dummyResult = calcResult dummyAdapters
58+
5759
print $ counts dummyResult
5860
print $ counts $ calcResult dummyAdapters2
5961

6062
contents <- readFile "10.input"
6163
let adapters = map (read @Int) $ lines contents
62-
print $ counts $ calcResult adapters -- have to add +1 to the count for three, not yet sure why
64+
print $ counts $ calcResult adapters
6365

0 commit comments

Comments
 (0)