Day 01
This commit is contained in:
14
01/build.zig
Normal file
14
01/build.zig
Normal file
@@ -0,0 +1,14 @@
|
||||
const Builder = @import("std").build.Builder;
|
||||
|
||||
pub fn build(b: *Builder) void {
|
||||
const mode = b.standardReleaseOptions();
|
||||
const exe = b.addExecutable("01", "src/main.zig");
|
||||
exe.setBuildMode(mode);
|
||||
exe.install();
|
||||
|
||||
const run_cmd = exe.run();
|
||||
run_cmd.step.dependOn(b.getInstallStep());
|
||||
|
||||
const run_step = b.step("run", "Run the app");
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
}
|
100
01/input
Normal file
100
01/input
Normal file
@@ -0,0 +1,100 @@
|
||||
109067
|
||||
75007
|
||||
66030
|
||||
93682
|
||||
83818
|
||||
108891
|
||||
139958
|
||||
129246
|
||||
80272
|
||||
119897
|
||||
112804
|
||||
69495
|
||||
95884
|
||||
85402
|
||||
148361
|
||||
75986
|
||||
120063
|
||||
127683
|
||||
146962
|
||||
76907
|
||||
61414
|
||||
98452
|
||||
134330
|
||||
53858
|
||||
82662
|
||||
143258
|
||||
82801
|
||||
60279
|
||||
131782
|
||||
105989
|
||||
102464
|
||||
96563
|
||||
71172
|
||||
113731
|
||||
90645
|
||||
94830
|
||||
133247
|
||||
110149
|
||||
54792
|
||||
134863
|
||||
125919
|
||||
145490
|
||||
69836
|
||||
108808
|
||||
87954
|
||||
148957
|
||||
110182
|
||||
126668
|
||||
148024
|
||||
96915
|
||||
117727
|
||||
147378
|
||||
75967
|
||||
91915
|
||||
60130
|
||||
85331
|
||||
66800
|
||||
103419
|
||||
72627
|
||||
72687
|
||||
61606
|
||||
113160
|
||||
107082
|
||||
110793
|
||||
61589
|
||||
105005
|
||||
73952
|
||||
65705
|
||||
117243
|
||||
140944
|
||||
117091
|
||||
113482
|
||||
91379
|
||||
148185
|
||||
113853
|
||||
119822
|
||||
78179
|
||||
85407
|
||||
119886
|
||||
109230
|
||||
68783
|
||||
63914
|
||||
51101
|
||||
93549
|
||||
53361
|
||||
127984
|
||||
106315
|
||||
54997
|
||||
138941
|
||||
81075
|
||||
120272
|
||||
120307
|
||||
98414
|
||||
115245
|
||||
105649
|
||||
89793
|
||||
88421
|
||||
121104
|
||||
97084
|
||||
56928
|
33
01/src/main.zig
Normal file
33
01/src/main.zig
Normal file
@@ -0,0 +1,33 @@
|
||||
const std = @import("std");
|
||||
|
||||
fn rocket(in: i64) i64 {
|
||||
var x: i64 = @divFloor(in, 3) - 2;
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
pub fn main() anyerror!void {
|
||||
const file = std.io.getStdIn();
|
||||
const stream = &file.inStream().stream;
|
||||
|
||||
var buf: [20]u8 = undefined;
|
||||
var sum1: i64 = 0; // part 1
|
||||
var sum2: i64 = 0; // part 2
|
||||
|
||||
while (try stream.readUntilDelimiterOrEof(&buf, '\n')) |line| {
|
||||
const mass = try std.fmt.parseInt(i64, line, 10);
|
||||
var rock = rocket(mass);
|
||||
sum1 += rock;
|
||||
while (rock > 0) {
|
||||
sum2 += rock;
|
||||
rock = rocket(rock);
|
||||
}
|
||||
}
|
||||
|
||||
std.debug.warn("Part 1: {}\n", sum1);
|
||||
std.debug.warn("Part 2: {}\n", sum2);
|
||||
}
|
||||
|
Reference in New Issue
Block a user