Compare commits
2 commits
8861ce0b8e
...
9a81f47677
Author | SHA1 | Date | |
---|---|---|---|
9a81f47677 | |||
6bf0d44e09 |
1 changed files with 38 additions and 36 deletions
|
@ -1,44 +1,46 @@
|
||||||
const std = @import("std");
|
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 util = @import("util.zig");
|
||||||
|
const Allocator = std.mem.Allocator;
|
||||||
|
const ArrayList = std.ArrayList;
|
||||||
|
const tokenize = std.mem.tokenize;
|
||||||
|
const print = std.debug.print;
|
||||||
const gpa = util.gpa;
|
const gpa = util.gpa;
|
||||||
|
|
||||||
const data = @embedFile("../data/day03.txt");
|
const data = @embedFile("input");
|
||||||
|
|
||||||
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});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Useful stdlib functions
|
fn count_trees(slope: [][]bool, delta_x: usize, delta_y: usize) usize {
|
||||||
const tokenize = std.mem.tokenize;
|
var x: usize = 0;
|
||||||
const split = std.mem.split;
|
var y: usize = 0;
|
||||||
const indexOf = std.mem.indexOfScalar;
|
var count: usize = 0;
|
||||||
const indexOfAny = std.mem.indexOfAny;
|
while (y < slope.len) {
|
||||||
const indexOfStr = std.mem.indexOfPosLinear;
|
var square = slope[y][x];
|
||||||
const lastIndexOf = std.mem.lastIndexOfScalar;
|
if (square) {
|
||||||
const lastIndexOfAny = std.mem.lastIndexOfAny;
|
count += 1;
|
||||||
const lastIndexOfStr = std.mem.lastIndexOfLinear;
|
}
|
||||||
const trim = std.mem.trim;
|
x = std.math.mod(usize, x + delta_x, slope[y].len) catch 0;
|
||||||
const sliceMin = std.mem.min;
|
y += delta_y;
|
||||||
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