~misterio/veraoPFPA-Listas

61d15f86ac0c177f473ddad5244b4e3d1dbe87f6 — Gabriel Fontes 5 months ago e65b79c
exercicio 9-b
1 files changed, 16 insertions(+), 0 deletions(-)

A 9-b.hs
A 9-b.hs => 9-b.hs +16 -0
@@ 0,0 1,16 @@
module Main where

type Peso = Int

combustivelNescessario :: Peso -> Peso
combustivelNescessario x
  | c <= 0 = 0
  | otherwise = c + combustivelNescessario c
  where
    c = (x `div` 3) - 2

main = do
  linhas <- lines <$> readFile "componentes.txt"
  let componentes = read <$> linhas
  let combustivelTotal = sum $ combustivelNescessario <$> componentes
  print combustivelTotal