gqG
This commit is contained in:
parent
4bbed10f38
commit
1bb30457aa
|
@ -1,6 +1,6 @@
|
|||
import Data.Char
|
||||
import Data.Function (on)
|
||||
import Data.List
|
||||
import Data.Char
|
||||
|
||||
data Hand =
|
||||
C Int Int Int Int Int
|
||||
|
@ -27,7 +27,7 @@ handType (C x1 x2 x3 x4 x5) =
|
|||
where
|
||||
cList = sort $ map length $ group sList
|
||||
sList = sort [x1, x2, x3, x4, x5]
|
||||
j = length (filter (==1) sList)
|
||||
j = length (filter (== 1) sList)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
|
@ -35,17 +35,17 @@ main = do
|
|||
print $ day07 (parse False input)
|
||||
print $ day07 (parse True input)
|
||||
|
||||
|
||||
day07 :: [(Hand, Int)] -> Int
|
||||
day07 = sum . zipWith (*) [1..] . map snd . sort
|
||||
day07 = sum . zipWith (*) [1 ..] . map snd . sort
|
||||
|
||||
parse :: Bool -> String -> [(Hand, Int)]
|
||||
parse p2 = map (f . words) . lines
|
||||
where f [x,y] = (parseHand x, read y)
|
||||
f x = error ("parse: Malformed input: " ++ show x)
|
||||
parseHand = g . map (digitToCard p2)
|
||||
g [x1, x2, x3, x4, x5] = C x1 x2 x3 x4 x5
|
||||
g x = error ("parseHand: Malformed input: " ++ show x)
|
||||
where
|
||||
f [x, y] = (parseHand x, read y)
|
||||
f x = error ("parse: Malformed input: " ++ show x)
|
||||
parseHand = g . map (digitToCard p2)
|
||||
g [x1, x2, x3, x4, x5] = C x1 x2 x3 x4 x5
|
||||
g x = error ("parseHand: Malformed input: " ++ show x)
|
||||
|
||||
digitToCard :: Bool -> Char -> Int
|
||||
digitToCard p2 x
|
||||
|
|
Loading…
Reference in New Issue
Block a user