Initial commit with Day 1, 2 and part of 3
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
22
day01/Day01.hs
Normal file
22
day01/Day01.hs
Normal file
@@ -0,0 +1,22 @@
|
||||
main :: IO()
|
||||
main = do
|
||||
inputText <- getContents
|
||||
let inputValues = map read (lines inputText)
|
||||
putStr "Part 1: "
|
||||
putStrLn $ show (part1 inputValues)
|
||||
putStr "Part 2: "
|
||||
putStrLn $ show (part2 inputValues)
|
||||
|
||||
part1 :: [Int] -> Int
|
||||
part1 numbers = sum $ map fuelReq numbers
|
||||
|
||||
fuelReq :: Int -> Int
|
||||
fuelReq mass = max 0 ((mass `div` 3) - 2)
|
||||
|
||||
part2 :: [Int] -> Int
|
||||
part2 numbers = sum $ map fullFuelReq numbers
|
||||
|
||||
fullFuelReq :: Int -> Int
|
||||
fullFuelReq mass =
|
||||
if fuelReq mass == 0 then 0
|
||||
else (fuelReq mass) + (fullFuelReq $ fuelReq mass)
|
||||
Reference in New Issue
Block a user