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 | |
parent | 0dc33cafed11aa4574f740b244d96060008ec714 (diff) |
shorten day07
-rw-r--r-- | execs/Day07.hs | 8 | ||||
-rw-r--r-- | lib/Utils.hs | 2 |
2 files changed, 4 insertions, 6 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 |
diff --git a/lib/Utils.hs b/lib/Utils.hs index 4c9a581..4319714 100644 --- a/lib/Utils.hs +++ b/lib/Utils.hs | |||
@@ -33,4 +33,4 @@ bet k (l, u) = k >= l && k <= u | |||
33 | (&+) = liftM2 (&&) | 33 | (&+) = liftM2 (&&) |
34 | 34 | ||
35 | howMany :: (a -> Bool) -> [a] -> Int | 35 | howMany :: (a -> Bool) -> [a] -> Int |
36 | howMany predicate = length . filter ((== True) . predicate) | 36 | howMany predicate = length . filter predicate |