|
|
|
|
@ -99,16 +99,16 @@ pub fn rule1Test(input: []Symbol ) bool{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
pub fn rule1(input: []Symbol) ![]Symbol{
|
|
|
|
|
std.debug.print("Rule1\n", .{});
|
|
|
|
|
// Ends on I? Add U.
|
|
|
|
|
|
|
|
|
|
// Allocate space for new array
|
|
|
|
|
var arr = try std.heap.page_allocator.alloc(Symbol, input.len + 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//copy input into the allocated array
|
|
|
|
|
// Assignment doesn't work, that also changes the length of the destination.
|
|
|
|
|
//NOTE: 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});
|
|
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -117,19 +117,7 @@ pub fn rule2Test(input: []Symbol) bool {
|
|
|
|
|
}
|
|
|
|
|
pub fn rule2(input: []Symbol) ![]Symbol{
|
|
|
|
|
//M_ => M__
|
|
|
|
|
|
|
|
|
|
std.debug.print("Rule2\n", .{});
|
|
|
|
|
|
|
|
|
|
// var arr = try std.heap.page_allocator.alloc(Symbol, input.len * 2);
|
|
|
|
|
|
|
|
|
|
// arr = input[0..];
|
|
|
|
|
// arr[input.len] = input[1..];
|
|
|
|
|
|
|
|
|
|
// mem.copy([]Symbol, arr)
|
|
|
|
|
|
|
|
|
|
const arr = mem.concat(std.heap.page_allocator, Symbol, &[_][]Symbol{input[0..], input[1..]});
|
|
|
|
|
std.debug.print("Rule2 result: {any}\n", .{arr});
|
|
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|