diff --git a/day_7/code b/day_7/code index 0dbb9f9..9476f10 100644 Binary files a/day_7/code and b/day_7/code differ diff --git a/day_7/code.hi b/day_7/code.hi index bcc6ae0..6028f0e 100644 Binary files a/day_7/code.hi and b/day_7/code.hi differ diff --git a/day_7/code.hs b/day_7/code.hs index 70e0db5..b163651 100644 --- a/day_7/code.hs +++ b/day_7/code.hs @@ -26,6 +26,8 @@ minimumsSnd [] = [] minimumsSnd xs = filter ((==) minsnd . snd) xs where minsnd = minimum (map snd xs) +sumK n = ((n+1)*n) `div` 2 + main :: IO () main = do input <- getContents @@ -35,11 +37,11 @@ main = do splitStr "," input } let cases = do { - map (\x -> (x, sum (map (\y -> do { - sum [1..((abs (y-x)))] - }) crabs))) [(minimum crabs)..(maximum crabs)] + map + (\x -> (x, sum (map (\y -> sumK (abs (y-x))) crabs))) + [(minimum crabs)..(maximum crabs)] } let min = minimumsSnd putStrLn $ show $ snd $ head $ min cases -- ans to part 2 --- C'est un code pas du tout efficace \ No newline at end of file +-- Gross, but it works \ No newline at end of file diff --git a/day_7/code.o b/day_7/code.o index baa859e..756f16b 100644 Binary files a/day_7/code.o and b/day_7/code.o differ