Day 4 Part 1
This commit is contained in:
100
day-01/input.txt
Normal file
100
day-01/input.txt
Normal file
@@ -0,0 +1,100 @@
|
||||
51360
|
||||
95527
|
||||
72603
|
||||
128601
|
||||
68444
|
||||
138867
|
||||
67294
|
||||
134343
|
||||
62785
|
||||
53088
|
||||
134635
|
||||
137884
|
||||
97654
|
||||
103704
|
||||
138879
|
||||
87561
|
||||
83922
|
||||
68414
|
||||
84876
|
||||
105143
|
||||
76599
|
||||
98924
|
||||
57080
|
||||
63590
|
||||
50126
|
||||
111872
|
||||
55754
|
||||
64410
|
||||
78488
|
||||
56557
|
||||
105446
|
||||
127182
|
||||
59451
|
||||
87249
|
||||
61652
|
||||
131698
|
||||
148820
|
||||
95742
|
||||
68223
|
||||
121744
|
||||
65678
|
||||
99745
|
||||
64089
|
||||
75610
|
||||
106085
|
||||
100364
|
||||
116959
|
||||
122862
|
||||
56580
|
||||
109631
|
||||
82895
|
||||
79666
|
||||
133474
|
||||
50579
|
||||
83473
|
||||
140028
|
||||
125999
|
||||
68225
|
||||
131345
|
||||
90797
|
||||
84914
|
||||
81915
|
||||
65369
|
||||
71230
|
||||
50379
|
||||
106385
|
||||
118503
|
||||
119640
|
||||
138540
|
||||
70678
|
||||
95881
|
||||
100282
|
||||
123060
|
||||
147368
|
||||
93030
|
||||
82553
|
||||
131271
|
||||
147675
|
||||
111126
|
||||
115183
|
||||
82956
|
||||
145698
|
||||
99261
|
||||
52768
|
||||
99207
|
||||
123551
|
||||
64738
|
||||
117275
|
||||
98136
|
||||
111592
|
||||
78576
|
||||
118613
|
||||
130351
|
||||
68567
|
||||
72356
|
||||
85608
|
||||
129414
|
||||
66521
|
||||
76924
|
||||
130449
|
||||
24
day-01/main.nim
Normal file
24
day-01/main.nim
Normal file
@@ -0,0 +1,24 @@
|
||||
import math, strutils
|
||||
|
||||
proc fuelCalc(mass: int): int =
|
||||
floor(mass / 3).toInt - 2
|
||||
|
||||
|
||||
proc calcForFuel(fuelMass: int): int =
|
||||
let required = fuelCalc(fuelMass)
|
||||
if required <= 0:
|
||||
return 0
|
||||
else:
|
||||
return required + calcForFuel(required)
|
||||
|
||||
proc calc(mass: int): int =
|
||||
var massFuel = fuelCalc(mass)
|
||||
var fuelFuel = calcForFuel(massFuel)
|
||||
return massFuel + fuelFuel
|
||||
|
||||
var result = 0;
|
||||
var file = open("input.txt", fmRead);
|
||||
for line in file.lines:
|
||||
result += calc(line.parseInt)
|
||||
|
||||
echo result
|
||||
Reference in New Issue
Block a user