From 061a5bae272f45db6dcde99746922735f9769d25 Mon Sep 17 00:00:00 2001 From: Christian Segundo Date: Mon, 5 Dec 2022 17:00:08 +0100 Subject: add day 5 --- util/aoc.zig | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 util/aoc.zig (limited to 'util/aoc.zig') diff --git a/util/aoc.zig b/util/aoc.zig new file mode 100644 index 0000000..0c3e668 --- /dev/null +++ b/util/aoc.zig @@ -0,0 +1,20 @@ +const std = @import("std"); + +pub const Result = union(enum) { + int: i32, + string: []const u8, + + pub fn cmp(self: Result, result: Result) bool { + switch (self) { + .int => |i| return i == result.int, + .string => |s| return std.mem.eql(u8, s, result.string), + } + } + + pub fn deinit(self: Result, allocator: std.mem.Allocator) void { + switch (self) { + .string => |s| return allocator.free(s), + else => {}, + } + } +}; -- cgit v1.2.3