From bbe358123c653438963826025c69e6ab86e4733a Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Fri, 11 Dec 2020 09:27:34 +0000 Subject: [PATCH] Better height field validation --- advent04/src/advent04.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/advent04/src/advent04.hs b/advent04/src/advent04.hs index 1960f86..f272645 100644 --- a/advent04/src/advent04.hs +++ b/advent04/src/advent04.hs @@ -14,7 +14,7 @@ import qualified Control.Applicative as CA import qualified Data.Map.Strict as M import qualified Data.Set as S import Data.Char -import Data.List +-- import Data.List -- import Text.Megaparsec.Debug @@ -29,7 +29,7 @@ main :: IO () main = do text <- TIO.readFile "data/advent04.txt" let passports = successfulParse text - -- print $ length passports + print $ length passports putStrLn $ runTests print $ part1 passports print $ part2 passports @@ -62,12 +62,12 @@ validRanged lower upper value = where v = read @Int value validHeight value = - if "cm" `isSuffixOf` value + if u == "cm" then validRanged 150 193 v - else if "in" `isSuffixOf` value + else if u == "in" then validRanged 59 76 v else False - where v = reverse $ drop 2 $ reverse value + where (v, u) = span isDigit value validHex value = (length value == 7) && (head value == '#') && (all isHexDigit $ tail value) -- 2.34.1