-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday1.el
26 lines (22 loc) · 982 Bytes
/
day1.el
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
(defun fuel-required (mass)
(- (floor (/ mass 3)) 2))
(defconst masses '(132709 102150 126463 85035 77219 86458 119251
121098 118730 122505 127964 68004 55833 77664 142865 124503
115892 87236 122743 127096 94893 62129 56520 117000 81519 121719
96291 96556 79006 137122 124340 125151 51603 50132 67568 132599
149009 60997 99382 96506 57269 118133 115119 126208 101098 60514
146171 70314 76473 51209 99190 57647 126985 142055 99615 146442
129520 145334 57799 87148 118362 80407 106449 57146 129035 60156
120016 147383 68819 83868 81021 131594 137692 86537 110709 127678
106849 137640 108482 131412 70331 90118 117557 117347 84688
108869 145359 127024 100976 90419 53362 106100 129474 56101 99975
79211 99865 121099 74511 123172))
(apply '+ (mapcar 'fuel-required masses))
; => 3393938
(defun fuel-required2 (mass)
(let ((fuel (- (floor (/ mass 3)) 2)))
(if (> fuel 0)
(+ fuel (fuel-required2 fuel))
0)))
(apply '+ (mapcar 'fuel-required2 masses))
; => 5088037