|
@@ -1,6 +1,6 @@
|
1
|
1
|
{-# LANGUAGE OverloadedStrings #-}
|
2
|
2
|
module Day1.Internal (
|
3
|
|
- elfToCalories,
|
|
3
|
+ parseElfInput,
|
4
|
4
|
Elf,
|
5
|
5
|
CalorieCount,
|
6
|
6
|
calories,
|
|
@@ -8,7 +8,7 @@ module Day1.Internal (
|
8
|
8
|
parseElfGroups,
|
9
|
9
|
intOrZero,
|
10
|
10
|
sortElves,
|
11
|
|
- caloriesOf
|
|
11
|
+ getCalories
|
12
|
12
|
) where
|
13
|
13
|
|
14
|
14
|
import qualified Data.Text as T
|
|
@@ -25,7 +25,7 @@ instance Show CalorieCount where
|
25
|
25
|
|
26
|
26
|
instance Show Elf where
|
27
|
27
|
show (Elf (CalorieCount c)) = "Elf[" ++ show c ++ "]"
|
28
|
|
-
|
|
28
|
+
|
29
|
29
|
instance Eq CalorieCount where
|
30
|
30
|
(==) (CalorieCount c1) (CalorieCount c2) = c1 == c2
|
31
|
31
|
|
|
@@ -41,17 +41,14 @@ elf c = Elf (CalorieCount c)
|
41
|
41
|
calories :: Int -> CalorieCount
|
42
|
42
|
calories = CalorieCount
|
43
|
43
|
|
44
|
|
-caloriesOf :: Elf -> Int
|
45
|
|
-caloriesOf (Elf (CalorieCount c)) = c
|
|
44
|
+getCalories :: Elf -> Int
|
|
45
|
+getCalories (Elf (CalorieCount c)) = c
|
46
|
46
|
|
47
|
47
|
sortElves :: [Elf] -> [Elf]
|
48
|
48
|
sortElves = L.reverse . L.sort
|
49
|
49
|
|
50
|
|
-elfToCalories :: T.Text -> [Elf]
|
51
|
|
-elfToCalories input = map elf sums
|
52
|
|
- where
|
53
|
|
- groups = parseElfGroups input
|
54
|
|
- sums = map sum groups
|
|
50
|
+parseElfInput :: T.Text -> [Elf]
|
|
51
|
+parseElfInput input = map (elf . sum) (parseElfGroups input)
|
55
|
52
|
|
56
|
53
|
parseElfGroups :: T.Text -> [[Int]]
|
57
|
54
|
parseElfGroups input = map (map intOrZero) groups
|