-
Notifications
You must be signed in to change notification settings - Fork 0
/
day1.rb
121 lines (117 loc) · 1011 Bytes
/
day1.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
def fuel_required(mass)
fuel = (mass/3).to_i - 2
if fuel > 0
fuel + fuel_required(fuel)
else
0
end
end
# p "Fuel for 1969 = #{fuel_required(1969)}"
# p "Fuel for 100756 = #{fuel_required(100756)}"
sum = 0
DATA.each_line do |line|
module_mass = line.to_i
sum += fuel_required(module_mass)
end
print "Total fuel required:\n#{sum}\n\n"
__END__
126360
61158
149929
88405
87526
51688
75356
116265
134986
111581
135675
69679
74035
144951
86157
68946
76761
114768
70694
84768
147379
78755
109688
118595
54608
77033
54654
61473
69644
81744
97148
106473
61541
98898
70394
117635
128388
140622
108691
126962
137756
125904
75675
127051
126388
85591
51583
101392
62959
135077
90916
127119
112427
79703
54739
50092
92505
53719
60887
62642
76382
85763
125799
67285
147992
80713
133619
131433
141765
109553
122534
88734
115622
82195
130771
121649
89355
121364
71664
130412
88936
63234
80274
108251
136663
139149
85052
67973
116461
75070
144261
106539
79712
116112
55755
121428
79362
103489
103157
64403