Refactor day1 into part1 function

This commit is contained in:
Adam Millerchip 2022-08-11 18:41:00 +09:00
parent 9c22642be4
commit 26f694c449

View file

@ -24,17 +24,20 @@ pub fn main() !void {
i = i + 1;
}
var answer: u32 = 0;
outer: for (buffer[0..i]) |a, j| {
for (buffer[(j+1)..i]) |b| {
try part1(buffer[0..i]);
}
fn part1(input: []u16) !void {
for (input) |a, i| {
for (input[(i+1)..]) |b| {
if (a + b == 2020) {
answer = @as(u32, a) * b;
break :outer;
const answer = @as(u32, a) * b;
print("Part1: {d}\n", .{answer});
return;
}
}
}
print("{d}\n", .{answer});
}
// Useful stdlib functions