Compare commits
No commits in common. "9a81f47677d7c765f605e57b85b1f285cacd2b7c" and "8861ce0b8ee651d939c529177443e2dbd9ea0720" have entirely different histories.
9a81f47677
...
8861ce0b8e
1 changed files with 36 additions and 38 deletions
|
@ -1,46 +1,44 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const util = @import("util.zig");
|
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
const ArrayList = std.ArrayList;
|
const List = std.ArrayList;
|
||||||
const tokenize = std.mem.tokenize;
|
const Map = std.AutoHashMap;
|
||||||
const print = std.debug.print;
|
const StrMap = std.StringHashMap;
|
||||||
|
const BitSet = std.DynamicBitSet;
|
||||||
|
const Str = []const u8;
|
||||||
|
|
||||||
|
const util = @import("util.zig");
|
||||||
const gpa = util.gpa;
|
const gpa = util.gpa;
|
||||||
|
|
||||||
const data = @embedFile("input");
|
const data = @embedFile("../data/day03.txt");
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
|
|
||||||
// Still have no idea how to clean up the ArrayLists
|
|
||||||
var it = tokenize(u8, data, "\n");
|
|
||||||
var rows_al = ArrayList([]bool).init(gpa);
|
|
||||||
while (it.next()) |line| {
|
|
||||||
var row = ArrayList(bool).init(gpa);
|
|
||||||
for (line) |char| {
|
|
||||||
try row.append(char == '#');
|
|
||||||
}
|
|
||||||
try rows_al.append(row.toOwnedSlice());
|
|
||||||
}
|
|
||||||
var rows = rows_al.toOwnedSlice();
|
|
||||||
|
|
||||||
var part_1 = count_trees(rows, 3, 1);
|
|
||||||
print("Part 1: {}\n", .{part_1});
|
|
||||||
|
|
||||||
var part_2 = count_trees(rows, 1, 1) * part_1 * count_trees(rows, 5, 1) * count_trees(rows, 7, 1) * count_trees(rows, 1, 2);
|
|
||||||
|
|
||||||
print("Part 2: {}\n", .{part_2});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn count_trees(slope: [][]bool, delta_x: usize, delta_y: usize) usize {
|
// Useful stdlib functions
|
||||||
var x: usize = 0;
|
const tokenize = std.mem.tokenize;
|
||||||
var y: usize = 0;
|
const split = std.mem.split;
|
||||||
var count: usize = 0;
|
const indexOf = std.mem.indexOfScalar;
|
||||||
while (y < slope.len) {
|
const indexOfAny = std.mem.indexOfAny;
|
||||||
var square = slope[y][x];
|
const indexOfStr = std.mem.indexOfPosLinear;
|
||||||
if (square) {
|
const lastIndexOf = std.mem.lastIndexOfScalar;
|
||||||
count += 1;
|
const lastIndexOfAny = std.mem.lastIndexOfAny;
|
||||||
}
|
const lastIndexOfStr = std.mem.lastIndexOfLinear;
|
||||||
x = std.math.mod(usize, x + delta_x, slope[y].len) catch 0;
|
const trim = std.mem.trim;
|
||||||
y += delta_y;
|
const sliceMin = std.mem.min;
|
||||||
}
|
const sliceMax = std.mem.max;
|
||||||
return count;
|
|
||||||
}
|
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;
|
||||||
|
|
Loading…
Add table
Reference in a new issue