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 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'execs') 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 -- cgit v1.2.3