Day 7
This commit is contained in:
24
day07/Part1.hs
Normal file
24
day07/Part1.hs
Normal file
@@ -0,0 +1,24 @@
|
||||
module Part1 where
|
||||
|
||||
import Commons
|
||||
import Data.List (sort, sortOn)
|
||||
|
||||
|
||||
getHandValueTypeFromSorted :: [Int] -> Int
|
||||
getHandValueTypeFromSorted [a, b, c, d, e] | a == e = 6
|
||||
| a == d || b == e = 5
|
||||
| a == c && d == e || a == b && c == e = 4
|
||||
| a == c || b == d || c == e = 3
|
||||
| a == b && (c == d || d == e) || b == c && d == e = 2
|
||||
| a == b || b == c || c == d || d == e = 1
|
||||
| otherwise = 0
|
||||
|
||||
getHandValue :: Hand -> HandValue
|
||||
getHandValue hand = HandValue {hand = hand, value = 100 ^ 5 * (getHandValueTypeFromSorted . sort) (values hand)
|
||||
+ getHandSecondValue (values hand)}
|
||||
|
||||
sortHands :: [Hand] -> [Hand]
|
||||
sortHands = map hand . sortHandValues . map getHandValue
|
||||
|
||||
getTotalWinnings :: [Hand] -> Int
|
||||
getTotalWinnings = getWinningsFromSorted 1 . sortHands
|
||||
Reference in New Issue
Block a user