summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--1/2.hs7
-rw-r--r--2/2.hs4
2 files changed, 6 insertions, 5 deletions
diff --git a/1/2.hs b/1/2.hs
index dd932d5..a5ba754 100644
--- a/1/2.hs
+++ b/1/2.hs
@@ -8,9 +8,10 @@ import System.Environment
 digits = ["one","two","three","four","five","six","seven","eight","nine"]
 
 parse [] = (mempty,mempty)
-parse l@(x:xs) = case findIndex (`isPrefixOf` l) digits of
-  Just i -> f (Just $ i+1) <> parse xs
-  Nothing -> f (readMaybe [x]) <> parse xs
+
+parse l@(x:xs)
+  | Just i <- findIndex (`isPrefixOf` l) digits = f (Just $ i+1) <> parse xs
+  | otherwise = f (readMaybe [x]) <> parse xs
   where
     f = (,) . First <*> Last
 
diff --git a/2/2.hs b/2/2.hs
index ed96a26..4437594 100644
--- a/2/2.hs
+++ b/2/2.hs
@@ -7,7 +7,7 @@ import Data.Maybe
 import qualified Data.Map as M
 import Control.Monad
 
-data Color = Red | Green | Blue deriving (Eq,Ord)
+data Color = Red | Green | Blue deriving (Show,Eq,Ord)
 type Handful = (Color, Int)
 type Set = M.Map Color Int
 type Game = (Int, [Set])
@@ -30,4 +30,4 @@ games = sepBy game newline
 solution :: Game -> Int
 solution = product . M.elems . M.unionsWith max . snd
 
-main = head <$> getArgs >>= readFile >>= print . sum . map solution . either (error.show) id . parse games ""
\ No newline at end of file
+main = head <$> getArgs >>= ((=<<) . ((print . sum . map solution . either (error . show) id) .) . parse games) <*> readFile
\ No newline at end of file