Numbers

From Esolang
Jump to navigation Jump to search

Numbers is astack-based esoteric programming language created by User:Xorol.

Instructions

An interpreter made by Xorol can be found here Interpreter

Numbers currently has these instructions:

Numbers' Instructions
Cmd Description
10 Adds the top two values on the stack
11 Subtracts the top two values on the stack
12 Multiplies the top two values on the stack
13 Divides the top two values on the stack
14 Divides the top two values on the stack and pushes the floored quotient
15 Divides the top two values on the stack and pushes the quotient and remainder
16 Increments the top value on the stack
17 Decrements the top value on the stack
18 Pushes the digital root of the top value on the stack
19 Pushes the factorial of the top value on the stack
20 Pushes the following value onto the stack
21 Reverses the stack
22 Swaps the top two values on the stack
23 Discards the top value on the stack
24 Sets the control accumulator's value to the top value on the stack and discards it
25 Pushes the control accumulator's value onto the stack
26 Duplicates the top value on the stack
27 Clears the stack
30 Outputs the top value on the stack
31 Outputs the top value on the stack as an ASCII character
32 Outputs the entire stack in the format "1st-item 2nd-item 3rd-item"
33 Outputs the entire stack as an ASCII string
34 Takes input from the user as an integer and pushes it onto the stack
35 Takes input from the user as an ASCII character and pushes its ASCII value onto the stack
36 Takes input from the user as an ASCII string and pushes each character's ASCII value onto the stack
40 Only does the next instruction if the control accumulator's value is not 0
41 Only does the net instruction if the control accumulator's value is 0
42 Goto
43 Repeats the program
~ Halts the program

Computational Class

Numbers is Turing-complete as every brainfuck instruction can be translated into it, given that the program starts with `20 0 20 0`.

Brainfuck Numbers
> 21 24 21 25
< 24 21 25 21
+ 20 1 10
- 20 1 11
. 31 23
, 35
[ 26 24 41 42 (the position of the end of the loop + 4 [to account for the goto statement])
] 26 24 40 42 (the position of the start of the loop)

Example programs

Hello, world!

The Hello World! program pushes each letter's corresponding ASCII values onto the stack, then prints the stack as a string

20 72 20 101 20 108 20 108 20 111 20 32 20 87 20 111 20 114 20 108 20 100 20 33 33

Truth-machine

The truth-machine takes input from the user, if it is a "1" it outputs "1"s indefinitely, if it's a "0" it outputs a singular "0"

34 26 24 40 42 9 30 ~ 30 42 9

Digital root calculator

It takes input from the user, and calculates the digital root using the formula 1+(n-1)%9. It takes advantage of the fact that the division instruction also pushes the remainder onto the stack.

34 18 30

Cat program

A cat program outputs whatever the user inputs

36 33