Skip to content

Instantly share code, notes, and snippets.

View mattfreire's full-sized avatar

Matthew Freire mattfreire

View GitHub Profile
@mattfreire
mattfreire / main.zig
Created September 21, 2023 09:24
Advent of code day 5
const std = @import("std");
const Stack = std.ArrayList(u8);
const Operation = struct { from: u8, to: u8, number: u8 };
pub fn create_stacks(allocator: std.mem.Allocator, stack_count: u8, it: *std.mem.SplitBackwardsIterator(u8, .any)) ![]Stack {
var stacks: []Stack = try allocator.alloc(Stack, stack_count);
for (stacks, 0..) |_, i| {
stacks[i] = Stack.init(allocator);
@mattfreire
mattfreire / main.zig
Created September 6, 2023 20:58
Advent of code day 4
const std = @import("std");
const ElfRange = struct { low: u8, high: u8 };
fn parse_u8(s: []const u8) !u8 {
const result = try std.fmt.parseInt(u8, s, 10);
return result;
}
fn parse_range(range: []const u8) !ElfRange {
@mattfreire
mattfreire / main.zig
Last active October 26, 2023 15:46
Advent of code day 3
const std = @import("std");
fn find_common(item: []const u8, allocator: std.mem.Allocator) !u8 {
// std.debug.print("{c}\n", .{item});
const half_length = item.len / 2;
const first_compartment = item[0..half_length];
const second_compartment = item[half_length..];
// std.debug.print("{c}\n", .{first_compartment});
// std.debug.print("{c}\n", .{second_compartment});
@mattfreire
mattfreire / main.zig
Created August 23, 2023 16:17
Advent of Code Day 2
const std = @import("std");
const Move = enum { rock, paper, scissors };
const Result = enum { win, draw, loss };
const EncryptionError = error{UnrecognizedInput};
fn decryptMyMove(input: u8) EncryptionError!Move {
const result: EncryptionError!Move = switch (input) {
@mattfreire
mattfreire / main.zig
Created August 15, 2023 16:46
Advent of Code Day 1
const std = @import("std");
pub fn main() !void {
std.debug.print("Hello World\n", .{});
const fileName = "day1.txt";
const file = try std.fs.cwd().openFile(fileName, .{});
defer file.close();
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);