From 7c26160075af3ccd87e0029ecc0e09ad3ca2dc66 Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 7 Dec 2020 12:38:50 +0530 Subject: shorten day07 --- execs/Day07.hs | 8 +++----- 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" parseContained :: [String] -> [(Int, String)] parseContained [] = [] +parseContained ("no":_) = [] parseContained (count:b:c:_:rest) = (read count, unwords [b,c]):parseContained rest parseLine :: [String] -> (String, [(Int, String)]) -parseLine s = (leadingBag, contained) - where leadingBag = unwords $ take 2 s +parseLine s = (leadingBag, parseContained trailingBags) + where leadingBag = unwords (take 2 s) trailingBags = drop 4 s - contained = case head trailingBags of - "no" -> [] - _ -> parseContained trailingBags canContain :: Map String [(Int, String)] -> String -> Bool 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 (&+) = liftM2 (&&) howMany :: (a -> Bool) -> [a] -> Int -howMany predicate = length . filter ((== True) . predicate) +howMany predicate = length . filter predicate -- cgit v1.2.3