You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.8 KiB
Zig
73 lines
1.8 KiB
Zig
const std = @import("std");
|
|
|
|
|
|
pub fn main() anyerror!void{
|
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
|
defer arena.deinit();
|
|
|
|
const allocator = &arena.allocator;
|
|
|
|
//format:
|
|
//[d-d] [c]: [password]
|
|
//[minamount [sperator] maxamount] [character]: [password]
|
|
|
|
var file = try std.fs.cwd().openFile("input2", .{});
|
|
defer file.close();
|
|
|
|
const file_size:u64 = try file.getEndPos();
|
|
std.debug.print("{0} \n", .{file_size});
|
|
|
|
//var buffer = try allocator.alloc(u8, file_size);
|
|
//var reader = file.reader();
|
|
|
|
//var size = try reader.read(buffer);
|
|
|
|
//std.debug.print("{0} \n", .{buffer});
|
|
try file.seekTo(0);
|
|
|
|
const contents = try file.reader().readAllAlloc(
|
|
allocator,
|
|
file_size
|
|
);
|
|
defer allocator.free(contents);
|
|
|
|
// const passBuffer = try allocator.alloc(u8, 40); //get a 40 char buffer
|
|
// defer allocator.free(passBuffer);
|
|
|
|
const ArrayList = std.ArrayList;
|
|
var list = ArrayList(u8).init(allocator);
|
|
defer list.deinit();
|
|
|
|
for(contents)|char,index|{
|
|
if(char == 12){
|
|
std.debug.print("\n", .{});
|
|
//end of line, so clear everything
|
|
|
|
continue;
|
|
}
|
|
if(char == 45){
|
|
//current char is (-), so we take the input so far
|
|
//and set it as the min
|
|
for(list)|didget|{
|
|
|
|
}
|
|
}
|
|
|
|
list.append(char);
|
|
|
|
//put byte in buffer
|
|
//is current byte a dash (-)?
|
|
//yes, then this is min
|
|
//read untill space
|
|
//from (-) until the space, is the max
|
|
|
|
std.debug.print("{c}", .{char});
|
|
|
|
}
|
|
}
|
|
|
|
pub fn isPassValid(char:u8, amountMin:i32, amountMax:i32, input: []u8 )bool{
|
|
//in here check if password is valid
|
|
return false;
|
|
|
|
} |