Skip to content

Instantly share code, notes, and snippets.

@wand125
Created December 11, 2013 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wand125/7905873 to your computer and use it in GitHub Desktop.
Save wand125/7905873 to your computer and use it in GitHub Desktop.
problem = "For theNumber in 0 to 100, if theNumber is divisible by 3 and theNumber is divisible by 5 then print 'FizzBuzz' else if theNumber is divisible by 3 then print 'Fizz' else if theNumber is divisible by 5 then print 'Buzz' else print theNumber.";
eval(problem.replace(/\./g,'').replace(/For (.*) in (\d+) to (\d+),/g,'for($1=$2;$1<=$3;$1++)').replace(/if (.+?) then/g,'if ($1)').replace(/print ([\w']+)/g,'console.log($1);').replace(/and/g,'&&').replace(/is divisible by (\d+)/g,'%$1==0'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment