commit 38b5f7abe355b00d9062fffff80303021f39c056
parent 4ca24e7c89556e46130635585a299b8119d92334
Author: amin <dev@aminmesbah.com>
Date: Mon, 2 Dec 2019 01:27:18 +0000
Add solution for 2019 01-1
FossilOrigin-Name: 8d286b38affbed1a80faef2315e5bd4507b4c088f0ee5242308732d51ee1f104
Diffstat:
A | day01_1.zig | | | 125 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 125 insertions(+), 0 deletions(-)
diff --git a/day01_1.zig b/day01_1.zig
@@ -0,0 +1,125 @@
+const std = @import("std");
+const dbg = std.debug;
+
+pub fn main() void {
+ var total_fuel: u32 = 0;
+ for (input) |mass, i| {
+ var module_fuel = get_fuel(mass);
+ total_fuel += module_fuel;
+ }
+ dbg.warn("Total fuel: {}\n", total_fuel);
+}
+
+fn get_fuel(mass: u32) u32 {
+ return (mass / 3) - 2;
+}
+
+test "get fuel" {
+ dbg.assert(get_fuel(12) == 2);
+ dbg.assert(get_fuel(14) == 2);
+ dbg.assert(get_fuel(1969) == 654);
+ dbg.assert(get_fuel(100756) == 33583);
+}
+
+const input = [_]u32{
+ 91617,
+ 134652,
+ 101448,
+ 83076,
+ 53032,
+ 80487,
+ 106061,
+ 103085,
+ 71513,
+ 143874,
+ 102830,
+ 121433,
+ 139937,
+ 104468,
+ 53098,
+ 75999,
+ 113915,
+ 73992,
+ 90028,
+ 64164,
+ 101248,
+ 111333,
+ 89201,
+ 89076,
+ 129360,
+ 81573,
+ 54381,
+ 64105,
+ 104272,
+ 144188,
+ 81022,
+ 125558,
+ 87910,
+ 135654,
+ 110929,
+ 131610,
+ 147160,
+ 139648,
+ 118129,
+ 93967,
+ 123117,
+ 77927,
+ 112034,
+ 84847,
+ 145527,
+ 72652,
+ 123043,
+ 136324,
+ 71228,
+ 118583,
+ 56992,
+ 141812,
+ 60119,
+ 105185,
+ 97653,
+ 134563,
+ 54195,
+ 64473,
+ 75606,
+ 148515,
+ 88765,
+ 112562,
+ 52156,
+ 119805,
+ 117149,
+ 149791,
+ 128964,
+ 108955,
+ 55806,
+ 86025,
+ 148350,
+ 74382,
+ 73632,
+ 141124,
+ 101688,
+ 106829,
+ 132594,
+ 113645,
+ 90320,
+ 104874,
+ 95210,
+ 118499,
+ 56445,
+ 86371,
+ 113833,
+ 122860,
+ 112507,
+ 55964,
+ 105993,
+ 92005,
+ 83760,
+ 90258,
+ 56238,
+ 127426,
+ 147641,
+ 129484,
+ 107162,
+ 99535,
+ 107975,
+ 136238,
+};