This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |