summaryrefslogtreecommitdiff
path: root/2017/2.hs
blob: 47ff1613355c86df223cd2d9331021c2a085e216 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
import Control.Monad

main :: IO ()
main = do
    input <- liftM (map (map read . words) . lines) (readFile "2.in") :: IO [[Int]]

    print $ sum [maximum l - minimum l | l <- input]

    let f = fst . head .
                filter ((/=1) . fst) . filter ((==0) . snd) .
                concat . concatMap (\(a,b) -> [map (a `divMod`) b, map (`divMod` a) b]) .
                (\l -> zip l (repeat l))
    print $ sum $ map f input