{-# Language QuasiQuotes #-}
module Main where
import Advent (format)
import Data.List (delete)
main :: IO ()
IO ()
main =
do xs <- [format|2017 2 (%u&%t%n)*|]
print (sum (map checksum1 xs))
print (sum (map checksum2 xs))
checksum1 :: [Int] -> Int
checksum1 :: [Int] -> Int
checksum1 [Int]
xs = [Int] -> Int
forall a. Ord a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum [Int]
xs Int -> Int -> Int
forall a. Num a => a -> a -> a
- [Int] -> Int
forall a. Ord a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [Int]
xs
checksum2 :: [Int] -> Int
checksum2 :: [Int] -> Int
checksum2 [Int]
xs =
[Int] -> Int
forall a. HasCallStack => [a] -> a
head [ Int
q | Int
x <- [Int]
xs, Int
y <- Int -> [Int] -> [Int]
forall a. Eq a => a -> [a] -> [a]
delete Int
x [Int]
xs, (Int
q,Int
0) <- [Int
x Int -> Int -> (Int, Int)
forall a. Integral a => a -> a -> (a, a)
`divMod` Int
y] ]