aboutsummaryrefslogtreecommitdiff
path: root/execs/Day07.hs
diff options
context:
space:
mode:
Diffstat (limited to 'execs/Day07.hs')
-rw-r--r--execs/Day07.hs8
1 files changed, 3 insertions, 5 deletions
diff --git a/execs/Day07.hs b/execs/Day07.hs
index 72043af..a0c1eb0 100644
--- a/execs/Day07.hs
+++ b/execs/Day07.hs
@@ -8,15 +8,13 @@ myBag = "shiny gold"
8 8
9parseContained :: [String] -> [(Int, String)] 9parseContained :: [String] -> [(Int, String)]
10parseContained [] = [] 10parseContained [] = []
11parseContained ("no":_) = []
11parseContained (count:b:c:_:rest) = (read count, unwords [b,c]):parseContained rest 12parseContained (count:b:c:_:rest) = (read count, unwords [b,c]):parseContained rest
12 13
13parseLine :: [String] -> (String, [(Int, String)]) 14parseLine :: [String] -> (String, [(Int, String)])
14parseLine s = (leadingBag, contained) 15parseLine s = (leadingBag, parseContained trailingBags)
15 where leadingBag = unwords $ take 2 s 16 where leadingBag = unwords (take 2 s)
16 trailingBags = drop 4 s 17 trailingBags = drop 4 s
17 contained = case head trailingBags of
18 "no" -> []
19 _ -> parseContained trailingBags
20 18
21canContain :: Map String [(Int, String)] -> String -> Bool 19canContain :: Map String [(Int, String)] -> String -> Bool
22canContain m outer = myBag `elem` inners || any (canContain m) inners 20canContain m outer = myBag `elem` inners || any (canContain m) inners