Rotten

From Esolang
Jump to navigation Jump to search

Rotten is a joke esolang whose programs can have 2 forms:

  • <string> - Implicitly converted to 13$<string>
  • <n>$<string> - Unescape the string (i.e. \n becomes a newline), with \i becoming a byte of input (if one doesn't exist then null bytes are assumed), then print it in ROT-<n>

Examples

Hello, World!

0$Hello, World! or Uryyb, Jbeyq!

Cat

(only works for 5 bytes of input)
\i\i\i\i\i

Fibonacci Sequence

Rotten is so convenient to program in, that if your program is a sequence, then the sequence elements (although only the ones you specified) are printed!
1, 1, 2, 3, 5, 8, 13
(prints 1, 1, 2, 3, 5, 8, 13)

Interpreter

Written in NodeJS.

function rotten(code)
{
  if(code.match(/^[0-9]+(, ?[0-9])*$/))
    console.log(code.replace(/,([^ ])/g, ", $1"));
  else if(code.match(/^[0-9]+\$/))
    console.log(rot(code.replace(/^[0-9]+\$/, ""), parseInt(code.split("$")[0])));
  else
    console.log(rot(code, 13))
}

function rot(s, n)
{
  let res = "";
  for(let i = 0; i < s.length; ++i)
  {
    if(s.charAt(i).match(/[A-Z]/))
    {
      res += String.fromCharCode((s.charCodeAt(i) - 65 + n) % 26 + 65);
    }
    else if(s.charAt(i).match(/[a-z]/))
    {
      res += String.fromCharCode((s.charCodeAt(i) - 97 + n) % 26 + 97);
    }
    else
    {
      res += s.charAt(i);
    }
  }
  return res;
}