added nicer error
This commit is contained in:
parent
f84cea91d5
commit
f7781d2f65
6
day1.hs
6
day1.hs
|
@ -16,10 +16,12 @@ solveA :: [Integer] -> Maybe Integer
|
||||||
solveA [] = Nothing
|
solveA [] = Nothing
|
||||||
solveA xs = Just $ (\(x,y) -> x * y) lsa
|
solveA xs = Just $ (\(x,y) -> x * y) lsa
|
||||||
where
|
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 :: [Integer] -> Maybe Integer
|
||||||
solveB [] = Nothing
|
solveB [] = Nothing
|
||||||
solveB xs = Just $ (\(x,y,z) -> x * y * z) lsb
|
solveB xs = Just $ (\(x,y,z) -> x * y * z) lsb
|
||||||
where
|
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 ]
|
||||||
|
|
Loading…
Reference in a new issue