|
|
|
|
@ -9,8 +9,6 @@ const Symbol = enum(u2) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pub fn main() !void {
|
|
|
|
|
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
|
|
|
|
|
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
|
|
|
|
|
|
|
|
|
|
// stdout is for the actual output of your application, for example if you
|
|
|
|
|
// are implementing gzip, then only the compressed bytes should be sent to
|
|
|
|
|
@ -24,61 +22,46 @@ pub fn main() !void {
|
|
|
|
|
var bag = std.ArrayList([]Symbol).init(std.heap.page_allocator);
|
|
|
|
|
defer bag.deinit(); // try commenting this out and see if zig detects the memory leak!
|
|
|
|
|
|
|
|
|
|
var initial: [2]Symbol = .{Symbol.M, Symbol.I};
|
|
|
|
|
//var initial: [2]Symbol = .{Symbol.M, Symbol.I};
|
|
|
|
|
var initial: [2]Symbol = .{Symbol.M, Symbol.U};
|
|
|
|
|
try bag.append(&initial);
|
|
|
|
|
|
|
|
|
|
var count: u64 = 0;
|
|
|
|
|
while(bag.items.len > count){
|
|
|
|
|
std.debug.print("curr/total {d}/{d}, \n", .{count, bag.items.len});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var currentBatch = bag.items[count..];
|
|
|
|
|
count = bag.items.len;
|
|
|
|
|
var currentBatch = bag.items;
|
|
|
|
|
|
|
|
|
|
std.debug.print("testing strings: {any}\n", .{currentBatch});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: skip to [count] items
|
|
|
|
|
for(currentBatch)|string|{
|
|
|
|
|
std.debug.print("Testing: {any}\n", .{string});
|
|
|
|
|
|
|
|
|
|
if(rule1Test(string)){ try bag.append(try rule1(string)); }
|
|
|
|
|
//if(rule1Test(string)){ try addToBag(bag,string);}
|
|
|
|
|
if(rule2Test(string)){ try bag.append(try rule2(string)); }
|
|
|
|
|
if(rule3Test(string)){ try bag.append(try rule3(string)); }
|
|
|
|
|
if(rule4Test(string)){ try bag.append(try rule4(string)); }
|
|
|
|
|
|
|
|
|
|
if(finish(string)){
|
|
|
|
|
break; //Finished!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std.debug.print("bag contains: {any}\n", .{bag.items});
|
|
|
|
|
|
|
|
|
|
std.debug.print("Testing: {any}\n", .{bag});
|
|
|
|
|
|
|
|
|
|
std.debug.print("curr/total {d}/{d}, \n", .{count, bag.items.len});
|
|
|
|
|
|
|
|
|
|
count = bag.items.len;
|
|
|
|
|
currentBatch = bag.items;
|
|
|
|
|
std.debug.print("testing strings: {any}\n", .{currentBatch});
|
|
|
|
|
|
|
|
|
|
// if(rule1Test(string)){ try bag.append(try rule1(string)); }
|
|
|
|
|
// if(rule2Test(string)){ try bag.append(try rule2(string)); }
|
|
|
|
|
// if(rule3Test(string)){ try bag.append(try rule3(string)); }
|
|
|
|
|
// if(rule4Test(string)){ try bag.append(try rule4(string)); }
|
|
|
|
|
|
|
|
|
|
if(rule1Test(string)){ try addToBag(bag,try rule1(string));}
|
|
|
|
|
if(rule2Test(string)){ try addToBag(bag,try rule2(string));}
|
|
|
|
|
if(rule3Test(string)){ try addToBag(bag,try rule3(string));}
|
|
|
|
|
if(rule4Test(string)){ try addToBag(bag,try rule4(string));}
|
|
|
|
|
|
|
|
|
|
for(currentBatch)|string|{
|
|
|
|
|
std.debug.print("Testing: {any}\n", .{string});
|
|
|
|
|
|
|
|
|
|
if(rule1Test(string)){ try bag.append(try rule1(string)); }
|
|
|
|
|
//if(rule1Test(string)){ try addToBag(bag,string);}
|
|
|
|
|
if(rule2Test(string)){ try bag.append(try rule2(string)); }
|
|
|
|
|
if(rule3Test(string)){ try bag.append(try rule3(string)); }
|
|
|
|
|
if(rule4Test(string)){ try bag.append(try rule4(string)); }
|
|
|
|
|
|
|
|
|
|
//TODO: Moet ik nog iets doen met het pad naar het anwoord?
|
|
|
|
|
if(finish(string)){
|
|
|
|
|
break; //Finished!
|
|
|
|
|
return; //Finished!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std.debug.print("bag contains: {any}\n", .{bag.items});
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -88,11 +71,15 @@ pub fn main() !void {
|
|
|
|
|
try bw.flush(); // don't forget to flush!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pub fn addToBag(list: std.ArrayList([]Symbol), new: []Symbol) !void{
|
|
|
|
|
// if(mem.containsAtLeast([]Symbol, list.items, 1, new)){
|
|
|
|
|
// try list.append(new);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
pub fn addToBag(list: std.ArrayList([]Symbol), new: []Symbol) !void{
|
|
|
|
|
|
|
|
|
|
std.debug.print("Does {any} exist in {any}\n", .{new, list.items});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(mem.containsAtLeast([]Symbol, list.items, 1, new)){
|
|
|
|
|
try list.append(new);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn rule1Test(input: []Symbol ) bool{
|
|
|
|
|
return (input[input.len-1] == Symbol.I);
|
|
|
|
|
@ -142,7 +129,6 @@ pub fn rule3(input: []Symbol) ![]Symbol{
|
|
|
|
|
var single = try std.heap.page_allocator.alloc(Symbol, 1);
|
|
|
|
|
single[0] = Symbol.U;
|
|
|
|
|
|
|
|
|
|
//var i:u64 = 0;
|
|
|
|
|
for(input)|symbol, i|{
|
|
|
|
|
if(symbol == Symbol.I){
|
|
|
|
|
var streak = input[i..i+2];
|
|
|
|
|
@ -191,7 +177,6 @@ pub fn rule4(input: []Symbol) ![]Symbol{
|
|
|
|
|
|
|
|
|
|
pub fn finish(input: []Symbol) bool{
|
|
|
|
|
const pattern: [2]Symbol = .{Symbol.M, Symbol.U};
|
|
|
|
|
|
|
|
|
|
return mem.eql(Symbol, input, &pattern);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|