Last active
September 26, 2016 04:30
-
-
Save tiago/b5a6fe555ce9993752b8989f6d91e70e to your computer and use it in GitHub Desktop.
Pixels Camp Challenge #2 - Core structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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