Part 2 on day 5
This commit is contained in:
parent
3b2cad32ab
commit
1d7c8f9996
10
app/5.hs
10
app/5.hs
@ -24,12 +24,14 @@ solve1 r l = sum $ filter (inOrder r []) l <&> (\a -> let t = length a in a !! (
|
|||||||
|
|
||||||
sort' :: Map Int [Int] -> [Int] -> [Int] -> [Int]
|
sort' :: Map Int [Int] -> [Int] -> [Int] -> [Int]
|
||||||
sort' _ p [] = p
|
sort' _ p [] = p
|
||||||
sort' r p (x:xs) = undefined
|
sort' r p (x:xs) = case Map.lookup x r of
|
||||||
|
Nothing -> sort' r (p ++ [x]) xs
|
||||||
|
Just l -> let t = p `intersect` l in sort' r ((p \\ t) ++ [x] ++ t) xs
|
||||||
|
|
||||||
solve2 :: Map Int [Int] -> [[Int]] -> Int
|
solve2 :: Map Int [Int] -> [[Int]] -> Int
|
||||||
solve2 r l = sum $ l <&> (\a -> let t = length a in a !! (t `div` 2)) . sort' r []
|
solve2 r l = sum $ filter (not . inOrder r []) l <&> (\a -> let t = length a in a !! (t `div` 2)) . sort' r []
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = readFile "inputs/5" <&> parse >>= \i ->
|
main = readFile "inputs/5" <&> parse >>= \i ->
|
||||||
print (uncurry solve1 i)
|
print (uncurry solve1 i) >>
|
||||||
--print (solve2 i)
|
print (uncurry solve2 i)
|
||||||
|
Loading…
Reference in New Issue
Block a user