From f7781d2f65c07b7d4e2df853b23bd54c5549f01e Mon Sep 17 00:00:00 2001 From: Thorn Avery Date: Tue, 1 Dec 2020 20:32:06 +1300 Subject: [PATCH] added nicer error --- day1.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/day1.hs b/day1.hs index e39e3e6..aca02ba 100644 --- a/day1.hs +++ b/day1.hs @@ -16,10 +16,12 @@ solveA :: [Integer] -> Maybe Integer solveA [] = Nothing solveA xs = Just $ (\(x,y) -> x * y) lsa where - lsa = head [ (x,y) | x <- xs, y <- xs, x + y == 2020 ] + lsa = if lsa' == [] then error "no answer" else head lsa' + lsa' = [ (x,y) | x <- xs, y <- xs, x + y == 2020 ] solveB :: [Integer] -> Maybe Integer solveB [] = Nothing solveB xs = Just $ (\(x,y,z) -> x * y * z) lsb where - lsb = head [ (x,y,z) | x <- xs, y <- xs, z <- xs, x + y + z == 2020 ] + lsb = if lsb' == [] then error "no answer" else head lsb' + lsb' = [ (x,y,z) | x <- xs, y <- xs, z <- xs, x + y + z == 2020 ]