day 7
This commit is contained in:
parent
6896c62cc8
commit
f57e712d38
4 changed files with 6 additions and 4 deletions
BIN
day_7/code
BIN
day_7/code
Binary file not shown.
BIN
day_7/code.hi
BIN
day_7/code.hi
Binary file not shown.
|
@ -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
|
||||
-- Gross, but it works
|
BIN
day_7/code.o
BIN
day_7/code.o
Binary file not shown.
Loading…
Reference in a new issue