diff options
author | Akshay <[email protected]> | 2020-12-07 07:08:50 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2020-12-07 07:08:50 +0000 |
commit | 7c26160075af3ccd87e0029ecc0e09ad3ca2dc66 (patch) | |
tree | f836453db8b62f5304d3fdb13f66df5939771b0d /execs | |
parent | 0dc33cafed11aa4574f740b244d96060008ec714 (diff) |
shorten day07
Diffstat (limited to 'execs')
-rw-r--r-- | execs/Day07.hs | 8 |
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 | ||
9 | parseContained :: [String] -> [(Int, String)] | 9 | parseContained :: [String] -> [(Int, String)] |
10 | parseContained [] = [] | 10 | parseContained [] = [] |
11 | parseContained ("no":_) = [] | ||
11 | parseContained (count:b:c:_:rest) = (read count, unwords [b,c]):parseContained rest | 12 | parseContained (count:b:c:_:rest) = (read count, unwords [b,c]):parseContained rest |
12 | 13 | ||
13 | parseLine :: [String] -> (String, [(Int, String)]) | 14 | parseLine :: [String] -> (String, [(Int, String)]) |
14 | parseLine s = (leadingBag, contained) | 15 | parseLine 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 | ||
21 | canContain :: Map String [(Int, String)] -> String -> Bool | 19 | canContain :: Map String [(Int, String)] -> String -> Bool |
22 | canContain m outer = myBag `elem` inners || any (canContain m) inners | 20 | canContain m outer = myBag `elem` inners || any (canContain m) inners |