Skip to content

Commit

Permalink
add solutions for 2015/03
Browse files Browse the repository at this point in the history
  • Loading branch information
demiazz committed Nov 13, 2024
1 parent 04155d7 commit 09db23a
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 0 deletions.
184 changes: 184 additions & 0 deletions native/solutions/2015/03/common.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
const std = @import("std");

const AnyReader = std.io.AnyReader;
const Direction = enum { north, south, east, west };

pub const Parser = struct {
is_end: bool,
is_invalid: bool,

reader: AnyReader,

pub fn init(reader: AnyReader) Parser {
return .{
.is_end = false,
.is_invalid = false,

.reader = reader,
};
}

pub fn read(self: *Parser) !Direction {
if (self.is_invalid) {
return error.InvalidInput;
}

if (self.is_end) {
return error.EndOfStream;
}

if (self.reader.readByte()) |byte| {
return switch (byte) {
'^' => .north,
'v' => .south,
'>' => .east,
'<' => .west,
'\n' => self.onEndOfStream(),
else => self.onInvalidInput(),
};
} else |err| {
return self.onError(err);
}
}

fn onError(self: *Parser, err: anyerror) anyerror!Direction {
switch (err) {
error.EndOfStream => return self.onEndOfStream(),
error.InvalidInput => return self.onInvalidInput(),
else => {
self.is_end = true;
self.is_invalid = true;

return err;
},
}
}

fn onEndOfStream(self: *Parser) !Direction {
self.is_end = true;

return error.EndOfStream;
}

fn onInvalidInput(self: *Parser) !Direction {
self.is_end = true;
self.is_invalid = true;

return error.InvalidInput;
}
};

pub const Point = struct {
x: i32,
y: i32,

pub fn init() Point {
return .{
.x = 0,
.y = 0,
};
}

pub fn move(self: *Point, dir: Direction) void {
switch (dir) {
.north => self.y += 1,
.south => self.y -= 1,
.east => self.x += 1,
.west => self.x -= 1,
}
}
};

fn checkInput(comptime input: []const u8, comptime output: []const Direction, is_valid: bool) !void {
var stream = std.io.fixedBufferStream(input);

var parser = Parser.init(stream.reader().any());

for (output) |expected| {
try std.testing.expectEqual(expected, parser.read());
}

const expected_error = if (is_valid) error.EndOfStream else error.InvalidInput;

try std.testing.expectError(expected_error, parser.read());
}

fn checkValidInput(comptime input: []const u8, comptime output: []const Direction) !void {
try checkInput(input, output, true);
}

fn checkInvalidInput(comptime input: []const u8, comptime output: []const Direction) !void {
try checkInput(input, output, false);
}

test "parser" {
try checkValidInput(
"",
&.{},
);

try checkValidInput(
"\n",
&.{},
);

try checkValidInput(
"^v><",
&.{
.north,
.south,
.east,
.west,
},
);

try checkValidInput(
"^v><\n",
&.{
.north,
.south,
.east,
.west,
},
);

try checkValidInput(
"^v><\n^v><",
&.{
.north,
.south,
.east,
.west,
},
);

try checkInvalidInput(
"^vV\n",
&.{
.north,
.south,
},
);
}

test "point" {
var point = Point.init();

try std.testing.expectEqual(Point{ .x = 0, .y = 0 }, point);

point.move(.north);

try std.testing.expectEqual(Point{ .x = 0, .y = 1 }, point);

point.move(.east);

try std.testing.expectEqual(Point{ .x = 1, .y = 1 }, point);

point.move(.south);

try std.testing.expectEqual(Point{ .x = 1, .y = 0 }, point);

point.move(.west);

try std.testing.expectEqual(Point{ .x = 0, .y = 0 }, point);
}
1 change: 1 addition & 0 deletions native/solutions/2015/03/input.fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
^^<<v<<v><v^^<><>^^<v<v^>>^^^><^>v^>v><><><<vv^^<^>^^<v^>v>v^v>>>^<>v<^<v^><^>>>>><<v>>^>>^>v^>><<^>v>v<>^v^v^vvv><>^^>v><v<><>^><^^<vv^v<v>^v>>^v^>v><>v^<vv>^><<v^>vv^<<>v>>><<<>>^<vv<^<>^^vv>>>^><<<<vv^v^>>><><^>v<>^>v<v^v<^vv><^v^><<<<>^<>v>^v>v<v<v<<>v<^<<<v>>>>>^^v>vv^^<>^<>^^^^<^^^v<v^^>v<^^v^^>v>^v^^^^>><<v<>v<>^v^<v<>><>^^><<^^<^^>vv<>v^<^v<vv<<<>^>^^>^<>v^^vv<>>v><<<>vvv<>v<>><^<^v<>^vv>^^v<v<v><^<>>vv<^>>^>>vv^v<vv^vv<^<<>>^v^<>^>>>>vv>^^>v>vv>v><^vv^<<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>v<v<^vv^v><^^<<vv>^<<v><>^>>>>><v^v<<<^>^v^v<<v<>vvv<<>v>v>>^v^v^>><<<<>v^<v<><<>>>^>>^>><<v>
43 changes: 43 additions & 0 deletions native/solutions/2015/03/part_1.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const panic = @import("panic");
const std = @import("std");

const common = @import("./common.zig");

const Allocator = std.mem.Allocator;
const AnyReader = std.io.AnyReader;
const Direction = common.Direction;
const Parser = common.Parser;
const Point = common.Point;

const Visited = std.hash_map.AutoHashMap(Point, void);

pub fn solve(allocator: Allocator, reader: AnyReader) ![]const u8 {
var parser = Parser.init(reader);

var visited = Visited.init(allocator);
defer visited.deinit();

var santa = Point.init();

while (parser.read()) |dir| {
santa.move(dir);

try visited.put(santa, undefined);
} else |err| {
if (err != error.EndOfStream) {
return err;
}
}

return try std.fmt.allocPrint(allocator, "{d}", .{visited.count()});
}

test "solution 2015/03/01" {
const input_file = @embedFile("./input.fixture");
var input = std.io.fixedBufferStream(input_file);

const answer = try solve(std.testing.allocator, input.reader().any());
defer std.testing.allocator.free(answer);

try std.testing.expectEqualStrings(answer, "2565");
}
54 changes: 54 additions & 0 deletions native/solutions/2015/03/part_2.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const panic = @import("panic");
const std = @import("std");

const common = @import("./common.zig");

const Allocator = std.mem.Allocator;
const AnyReader = std.io.AnyReader;
const Direction = common.Direction;
const Parser = common.Parser;
const Point = common.Point;

const Visited = std.hash_map.AutoHashMap(Point, void);

pub fn solve(allocator: Allocator, reader: AnyReader) ![]const u8 {
var parser = Parser.init(reader);

var visited = Visited.init(allocator);
defer visited.deinit();

var is_santa_will_move = true;

var santa = Point.init();
var robo_santa = Point.init();

while (parser.read()) |dir| {
if (is_santa_will_move) {
santa.move(dir);

try visited.put(santa, undefined);
} else {
robo_santa.move(dir);

try visited.put(robo_santa, undefined);
}

is_santa_will_move = !is_santa_will_move;
} else |err| {
if (err != error.EndOfStream) {
return err;
}
}

return try std.fmt.allocPrint(allocator, "{d}", .{visited.count()});
}

test "solution 2015/03/02" {
const input_file = @embedFile("./input.fixture");
var input = std.io.fixedBufferStream(input_file);

const answer = try solve(std.testing.allocator, input.reader().any());
defer std.testing.allocator.free(answer);

try std.testing.expectEqualStrings(answer, "2639");
}
2 changes: 2 additions & 0 deletions native/solutions/registry.zig
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ pub const items = [_]Entry{
entry(.year_2015, .day_01, .part_two, index.solver_2015_01_02),
entry(.year_2015, .day_02, .part_one, index.solver_2015_02_01),
entry(.year_2015, .day_02, .part_two, index.solver_2015_02_02),
entry(.year_2015, .day_03, .part_one, index.solver_2015_03_01),
entry(.year_2015, .day_03, .part_two, index.solver_2015_03_02),
};

pub fn lookup(year: Year, day: Day, part: Part) ?Solver {
Expand Down
2 changes: 2 additions & 0 deletions native/solutions/solutions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ pub const solver_2015_01_01 = @import("./2015/01/part_1.zig").solve;
pub const solver_2015_01_02 = @import("./2015/01/part_2.zig").solve;
pub const solver_2015_02_01 = @import("./2015/02/part_1.zig").solve;
pub const solver_2015_02_02 = @import("./2015/02/part_2.zig").solve;
pub const solver_2015_03_01 = @import("./2015/03/part_1.zig").solve;
pub const solver_2015_03_02 = @import("./2015/03/part_2.zig").solve;

test {
@import("std").testing.refAllDecls(@This());
Expand Down

0 comments on commit 09db23a

Please sign in to comment.