Skip to content

Instantly share code, notes, and snippets.

@tiago
Last active September 26, 2016 04:30
Show Gist options
  • Select an option

  • Save tiago/b5a6fe555ce9993752b8989f6d91e70e to your computer and use it in GitHub Desktop.

Select an option

Save tiago/b5a6fe555ce9993752b8989f6d91e70e to your computer and use it in GitHub Desktop.
Pixels Camp Challenge #2 - Core structure
var c = (program) => {
var register = undefined;
var memory = [0];
var memory_pointer = 0;
var instruction_pointer = 0;
var commands = {
moo: () => { console.log('moo'); },
mOo: () => { console.log('mOo'); },
moO: () => { console.log('moO'); },
mOO: () => { console.log('mOO'); },
Moo: () => { console.log('Moo'); },
MOo: () => { console.log('MOo'); },
MoO: () => { console.log('mOo'); },
MOO: () => { console.log('MOO'); },
OOO: () => { console.log('OOO'); },
MMM: () => { console.log('MMM'); },
OOM: () => { console.log('OOM'); },
oom: () => { console.log('oom'); }
};
var tokens = Object.keys(commands); // assuming key order (don't try this at home :)
var instructions = program.match(new RegExp(codes.join('|'), 'g'));
while (instruction_pointer >= 0 && instruction_pointer < instructions.length) {
var instruction = instructions[instruction_pointer];
commands[instruction]();
instruction_pointer++;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment