Day 1 part 2
This commit is contained in:
parent
26f694c449
commit
ba09492857
1 changed files with 18 additions and 37 deletions
|
@ -1,13 +1,7 @@
|
|||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const List = std.ArrayList;
|
||||
const Map = std.AutoHashMap;
|
||||
const StrMap = std.StringHashMap;
|
||||
const BitSet = std.DynamicBitSet;
|
||||
const Str = []const u8;
|
||||
|
||||
const util = @import("util.zig");
|
||||
const gpa = util.gpa;
|
||||
const tokenize = std.mem.tokenize;
|
||||
const parseInt = std.fmt.parseInt;
|
||||
const print = std.debug.print;
|
||||
|
||||
const data = @embedFile("../data/day01.txt");
|
||||
|
||||
|
@ -25,8 +19,10 @@ pub fn main() !void {
|
|||
}
|
||||
|
||||
try part1(buffer[0..i]);
|
||||
try part2(buffer[0..i]);
|
||||
}
|
||||
|
||||
|
||||
fn part1(input: []u16) !void {
|
||||
for (input) |a, i| {
|
||||
for (input[(i+1)..]) |b| {
|
||||
|
@ -37,33 +33,18 @@ fn part1(input: []u16) !void {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Useful stdlib functions
|
||||
const tokenize = std.mem.tokenize;
|
||||
const split = std.mem.split;
|
||||
const indexOf = std.mem.indexOfScalar;
|
||||
const indexOfAny = std.mem.indexOfAny;
|
||||
const indexOfStr = std.mem.indexOfPosLinear;
|
||||
const lastIndexOf = std.mem.lastIndexOfScalar;
|
||||
const lastIndexOfAny = std.mem.lastIndexOfAny;
|
||||
const lastIndexOfStr = std.mem.lastIndexOfLinear;
|
||||
const trim = std.mem.trim;
|
||||
const sliceMin = std.mem.min;
|
||||
const sliceMax = std.mem.max;
|
||||
|
||||
const parseInt = std.fmt.parseInt;
|
||||
const parseFloat = std.fmt.parseFloat;
|
||||
|
||||
const min = std.math.min;
|
||||
const min3 = std.math.min3;
|
||||
const max = std.math.max;
|
||||
const max3 = std.math.max3;
|
||||
|
||||
const print = std.debug.print;
|
||||
const assert = std.debug.assert;
|
||||
|
||||
const sort = std.sort.sort;
|
||||
const asc = std.sort.asc;
|
||||
const desc = std.sort.desc;
|
||||
fn part2(input: []u16) !void {
|
||||
for (input) |a, i| {
|
||||
for (input[(i+1)..]) |b, j| {
|
||||
for (input[(j+1)..]) |c| {
|
||||
if (a + b + c == 2020) {
|
||||
const answer = @as(u32, a) * b * c;
|
||||
print("Part2: {d}\n", .{answer});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue