aboutsummaryrefslogtreecommitdiff
path: root/execs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-12-07 07:08:50 +0000
committerAkshay <[email protected]>2020-12-07 07:08:50 +0000
commit7c26160075af3ccd87e0029ecc0e09ad3ca2dc66 (patch)
treef836453db8b62f5304d3fdb13f66df5939771b0d /execs
parent0dc33cafed11aa4574f740b244d96060008ec714 (diff)
shorten day07
Diffstat (limited to 'execs')
-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