34 lines
		
	
	
		
			730 B
		
	
	
	
		
			Zig
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			730 B
		
	
	
	
		
			Zig
		
	
	
	
	
	
const std = @import("std");
 | 
						|
 | 
						|
const input = @embedFile("input");
 | 
						|
 | 
						|
fn floorTester(in: []const u8) i32{
 | 
						|
    var floor: i32 = 0;
 | 
						|
    for (in) |c|{
 | 
						|
        switch (c){
 | 
						|
            '(' => floor += 1,
 | 
						|
            ')' => floor -= 1,
 | 
						|
            else => unreachable,
 | 
						|
        }
 | 
						|
    }
 | 
						|
    return floor;
 | 
						|
}
 | 
						|
 | 
						|
fn whenBasement(in: []const u8) ?usize{
 | 
						|
    var floor: i32 = 0;
 | 
						|
    for (in, 0..) |c, i|{
 | 
						|
        switch (c){
 | 
						|
            '(' => floor += 1,
 | 
						|
            ')' => floor -= 1,
 | 
						|
            else => unreachable,
 | 
						|
        }
 | 
						|
        if (floor < 0) return i+1;
 | 
						|
    }
 | 
						|
    return null;
 | 
						|
}
 | 
						|
 | 
						|
pub fn main() void{
 | 
						|
    std.debug.print("Is on floor {d}\n", .{floorTester(input)});
 | 
						|
    std.debug.print("Is in basement at {?}\n", .{whenBasement(input)});
 | 
						|
}
 |