Explorar el Código

added nicer error

master
Thorn Avery hace 3 años
padre
commit
f7781d2f65
Se han modificado 1 ficheros con 4 adiciones y 2 borrados
  1. +4
    -2
      day1.hs

+ 4
- 2
day1.hs Ver fichero

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

Cargando…
Cancelar
Guardar