-
-
Save llimllib/ff0fe7d3cff9a4b68039be6bed8189a6 to your computer and use it in GitHub Desktop.
This file contains 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 fs = std.fs; | |
const Map = std.ArrayList([]const u8); | |
pub fn parse(input: []u8, alloc: *std.mem.Allocator) Map { | |
var map = Map.init(alloc); | |
var lines = std.mem.tokenize(inputCopy, "\n"); | |
while (lines.next()) |line| { | |
map.append(line) catch unreachable; | |
} | |
return map; | |
} | |
pub fn printMap(map: Map) void { | |
var i: usize = 0; | |
while (i < map.items.len) : (i += 1) { | |
std.debug.print("{}\n", .{map.items[i]}); | |
} | |
} | |
test "parse" { | |
var alloc = std.heap.GeneralPurposeAllocator(.{}){}; | |
const maps = | |
\\L.LL.LL.LL | |
\\LLLLLLL.LL | |
\\L.L.L..L.. | |
\\LLLL.LL.LL | |
\\L.LL.LL.LL | |
\\L.LLLLL.LL | |
\\..L.L..... | |
\\LLLLLLLLLL | |
\\L.LLLLLL.L | |
\\L.LLLLL.LL | |
.*; | |
var map = parse(maps, &alloc.allocator); | |
printMap(map); | |
} | |
pub fn run(map: Map, alloc: *std.mem.Allocator) usize { | |
var map2: Map = map; | |
std.debug.print("\ntype: {}\n", .{@TypeOf(map2.items)}); | |
std.debug.print("{}\n", .{map2.items[0]}); | |
// map2.items[0][0] = '.'; | |
var openSeats: usize = 0; | |
return openSeats; | |
} | |
test "run" { | |
var alloc = std.heap.GeneralPurposeAllocator(.{}){}; | |
const maps = | |
\\L.LL.LL.LL | |
\\LLLLLLL.LL | |
\\L.L.L..L.. | |
\\LLLL.LL.LL | |
\\L.LL.LL.LL | |
\\L.LLLLL.LL | |
\\..L.L..... | |
\\LLLLLLLLLL | |
\\L.LLLLLL.L | |
\\L.LLLLL.LL | |
; | |
var map = parse(maps, &alloc.allocator); | |
var open = run(map, &alloc.allocator); | |
std.testing.expect(open == 0); | |
} | |
pub fn main() !void { | |
var alloc = std.heap.GeneralPurposeAllocator(.{}){}; | |
var args = try std.process.argsAlloc(&alloc.allocator); | |
const input = try std.fs.cwd().readFileAlloc(&alloc.allocator, args[1], std.math.maxInt(usize)); | |
var instructions = parse(input, &alloc.allocator); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment