Day3 part 1
This commit is contained in:
parent
8861ce0b8e
commit
6bf0d44e09
1 changed files with 27 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
const List = std.ArrayList;
|
const ArrayList = std.ArrayList;
|
||||||
const Map = std.AutoHashMap;
|
const Map = std.AutoHashMap;
|
||||||
const StrMap = std.StringHashMap;
|
const StrMap = std.StringHashMap;
|
||||||
const BitSet = std.DynamicBitSet;
|
const BitSet = std.DynamicBitSet;
|
||||||
|
@ -9,10 +9,34 @@ const Str = []const u8;
|
||||||
const util = @import("util.zig");
|
const util = @import("util.zig");
|
||||||
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 x: usize = 0;
|
||||||
|
var y: usize = 0;
|
||||||
|
var count: usize = 0;
|
||||||
|
while (y < rows.len) {
|
||||||
|
var square = rows[y][x];
|
||||||
|
if (square) {
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
x = try std.math.mod(usize, x + 3, rows[y].len);
|
||||||
|
y += 1;
|
||||||
|
}
|
||||||
|
print("{}", .{count});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Useful stdlib functions
|
// Useful stdlib functions
|
||||||
|
|
Loading…
Reference in a new issue