Refactor day1 into part1 function
This commit is contained in:
parent
9c22642be4
commit
26f694c449
1 changed files with 9 additions and 6 deletions
|
@ -24,17 +24,20 @@ pub fn main() !void {
|
||||||
i = i + 1;
|
i = i + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var answer: u32 = 0;
|
try part1(buffer[0..i]);
|
||||||
outer: for (buffer[0..i]) |a, j| {
|
}
|
||||||
for (buffer[(j+1)..i]) |b| {
|
|
||||||
|
fn part1(input: []u16) !void {
|
||||||
|
for (input) |a, i| {
|
||||||
|
for (input[(i+1)..]) |b| {
|
||||||
if (a + b == 2020) {
|
if (a + b == 2020) {
|
||||||
answer = @as(u32, a) * b;
|
const answer = @as(u32, a) * b;
|
||||||
break :outer;
|
print("Part1: {d}\n", .{answer});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print("{d}\n", .{answer});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Useful stdlib functions
|
// Useful stdlib functions
|
||||||
|
|
Loading…
Reference in a new issue