-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday1.hs
24 lines (17 loc) · 1.16 KB
/
day1.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
-- Day 1
shipModuleMasses :: [Int]
shipModuleMasses = [122281,124795,58593,133744,67625,109032,50156,80746,130872,79490,126283,146564,73075,130170,139853,92599,96965,58149,94254,89074,52977,148092,92073,136765,144755,142487,54827,135588,91411,51597,70040,68880,117120,137115,72829,100048,65187,131464,95813,146891,128799,94568,67178,94903,67193,127613,115782,85360,129820,50989,63471,106724,145768,55169,77555,82978,87728,69141,95518,82985,83387,83089,64372,127931,99277,58930,99098,95621,147797,64102,118857,71014,84881,147294,72166,71348,149240,117963,89181,144770,102444,99103,72341,56076,128515,51319,147595,98431,141102,148617,84685,111427,82351,57021,63834,113059,119970,87078,120631,124942]
fuelPerUnit :: Int -> Int
fuelPerUnit x = floor ((fromIntegral x) / 3) - 2
shipMassFuelCost :: [Int] -> Int
shipMassFuelCost n = sum (map fuelPerUnit n)
--- shipMassFuelCost shipModuleMasses
--- 3296560
moduleFuelCost :: Int -> Int
moduleFuelCost n
| fuelPerUnit n <= 0 = 0
| otherwise = fuelPerUnit n + moduleFuelCost (fuelPerUnit n)
shipTotalCost :: [Int] -> Int
shipTotalCost n = sum (map moduleFuelCost n)
--- shipTotalCost shipModuleMasses
--- 4941976