12

From Esolang
Jump to navigation Jump to search

12 isn't 11, 10, etc.. 12 just has 12 commands.

Commands

command description
+ increment
- decrement
. output (as number)
, output (as ASCII)
* multiply by 2
^ square
/ divide by 2
x change accumulator to XKCD Random Number
o zero accumulator
g change accumulator to googol
n change accumulator to 99
@ halt

Interpreter

Python

acc = 0
cmds = input(">")
for c in cmds:
    if c == '+': acc += 1
    elif c == '-': acc -= 1
    elif c == '*': acc *= 2
    elif c == '^': acc **= 2
    elif c == '/': acc //= 2
    elif c == 'x': acc = 4
    elif c == 'o': acc = 0
    elif c == 'g': acc = 10**100
    elif c == 'n': acc = 99
    elif c == '.': print(acc)
    elif c == ',': print(chr(acc % 256), end='')
    elif c == '@': break

JS

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.question('>', (cmds) => {
  let acc = 0n; 
  let output = '';

  for (const c of cmds) {
    switch (c) {
      case '+': acc += 1n; break;
      case '-': acc -= 1n; break;
      case '*': acc *= 2n; break;
      case '^': acc **= 2n; break;
      case '/': acc /= 2n; break; 
      case 'x': acc = 4n; break;
      case 'o': acc = 0n; break;
      case 'g': acc = 10n ** 100n; break;
      case 'n': acc = 99n; break;
      case '.': output += acc.toString() + '\n'; break;
      case ',': output += String.fromCharCode(Number(acc % 256n)); break;
      case '@': break;
    }
    if (c === '@') break;
  }

  process.stdout.write(output);
  rl.close();
});

Examples

Hello, World!

+++*^*,n++,+++++++,,+++,o+***-^-----,o+*****,o+***+^++++++,n++++++++++++,+++,n+++++++++,n+,o+*****+,

XKCD Random Number

x.