Fixed copy bug in rule 1

main
Tarik Hijstek 3 years ago
parent 7b02ebad93
commit 58464ff0ae

@ -54,6 +54,30 @@ pub fn main() !void {
std.debug.print("bag contains: {any}\n", .{bag.items});
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});
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});
return;
}
@ -78,7 +102,10 @@ pub fn rule1(input: []Symbol) ![]Symbol{
std.debug.print("Rule1\n", .{});
var arr = try std.heap.page_allocator.alloc(Symbol, input.len + 1);
arr = input[0..];
//copy input into the allocated array
// Assignment doesn't work, that also changes the length of the destination.
mem.copy(Symbol, arr, input[0..]);
arr[arr.len-1] = Symbol.U;
std.debug.print("Rule1 result: {any}\n", .{arr});
@ -110,7 +137,7 @@ pub fn rule3Test(input: []Symbol) bool {
const pattern: [3]Symbol = .{Symbol.I, Symbol.I, Symbol.I};
for(input)|symbol, i|{
if(symbol == Symbol.I){
if(symbol == Symbol.I and (i+2 < input.len)){
var streak = input[i..i+2];
if(mem.eql(Symbol, streak, &pattern) ){
return true;

Loading…
Cancel
Save