浏览代码

added nicer error

master
Thorn Avery 3 年前
父节点
当前提交
f7781d2f65
共有 1 个文件被更改,包括 4 次插入2 次删除
  1. +4
    -2
      day1.hs

+ 4
- 2
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 ]

正在加载...
取消
保存