aboutsummaryrefslogtreecommitdiff
path: root/2019/one.nim
diff options
context:
space:
mode:
Diffstat (limited to '2019/one.nim')
-rw-r--r--2019/one.nim16
1 files changed, 16 insertions, 0 deletions
diff --git a/2019/one.nim b/2019/one.nim
new file mode 100644
index 0000000..63c1219
--- /dev/null
+++ b/2019/one.nim
@@ -0,0 +1,16 @@
+# Day One: The Tyranny of the Rocket Equation
+import os, strutils
+
+let input: string = paramStr(1)
+var sum, fuelsum: int = 0
+
+for mass in lines(input):
+ var fuel = parseInt(mass) div 3 - 2
+ sum += fuel
+ fuelsum += fuel
+ while fuel > 0:
+ fuel = fuel div 3 - 2
+ fuelsum += max(0, fuel)
+
+echo sum
+echo fuelsum