esolang

Oasis

A program is the rule for the next term of a sequence. The first terms go at the end.

Adnan · Turing complete: unknown · ●●○ moderate

Tested with 7 known programs · Hello World on Try It Online: identical except the line end · Test method

Run it

Expected: Hello, World!

The idea

Adnan, who also made 05AB1E, wrote Oasis for integer sequences. A program says how to work out a(n) from earlier terms, and the digits at the end of the program are the first terms. bc+10 is the Fibonacci numbers. b pushes a(n-1), c pushes a(n-2), + adds, and the trailing 10 gives a(0) = 0 and a(1) = 1, read from the end.

Read the story

Every term is worked out once and remembered, so a(300) of the Fibonacci program is instant. A command that finds the stack empty takes earlier terms instead. That makes +10 the Fibonacci numbers too, and n*1 the factorials.

The machine

CommandDoes
0-9A number; at the very end, the first terms
nThe index n
b c da(n-1), a(n-2), a(n-3)
a ea(x), a(n-x)
+ - * / m % ÷Arithmetic; m is power, ÷ integer division
> < x y t v kPlus 1, minus 1, double, triple, halve, integer halve, square
! p _ AFactorial, is prime, is 0, is 1
"text"A string

The index comes from the first line of input; Try It Online passes it as an argument. The answer is printed with a newline. A command that fails, such as a division by zero, is skipped without a word.

Example

bx1 doubles the term before it, starting from 1.
Expected: 55
Expected: 120
Expected: 1024

bx1 doubles the term before it, starting from 1. The square of a negative number comes out negative, since the reference hands Python the text -3** 2.

Patterns it teaches

  • Code golf: the recursion and its base case cost nothing to write.
  • Stack machines: an empty stack is not an error but a way to name the terms before.

Try this

  1. Print the triangular numbers, a(n) = a(n-1) + n.
  2. Print 3 to the power n.
  3. Hard: the number of steps in the Collatz sequence of n.

Further

Also in Golfing

Write your own in Run Convert a program from Oasis

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: oasis.

Command line

shib run oasis -e '+T' --input '12'
shib manual oasis

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/oasis.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language