added nicer error

This commit is contained in:
Thorn Avery 2020-12-01 20:32:06 +13:00
parent f84cea91d5
commit f7781d2f65

View file

@ -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 ]