33

From Esolang
Jump to navigation Jump to search

33 is the name of a simple and original esolang invented by TheOnlyMrCat. The language has exactly 33 alphabetical single-character commands which do certain functions (hence the name).

A design aim of 33 was to have a plethora of alphabetic character-commands, rather than only non-alphabetic characters which most other esolangs use (Although the language does bear some valid non-alphabetic commands).

Syntax

Unlike other programming languages, which hypothetically have an infinite supply of memory, 33 programs (not thirty-three programs) contain only 7 memory spaces:

  • 2 integer registers
    • The Accumulator
    • The Counter
  • 2 string registers
    • The Source
    • The Destination
  • 2 list registers
    • The Mutable List
    • The Backup List
  • 1 dictionary register
    • The General Integer Memory

All of the registers are initially nullified, meaning that the integers are set to 0, and strings, lists and dictionaries are empty.

Each of these variables interact with each other to make the program function.

Functions

There is also a dictionary which stores individual functions, which can be evaluated using the q alphacommand. This dictionary can be filled with code snippets, with a respective name. When a { command is reached, the program parses everything after until it finds a corresponding }. The parsed snippet is save onto the functions dictionary, with its respective name being set to the destination string.

When the q alphacommand has been found, the program searches for a function with the name equal to the source string. If it is found, then the function is excecuted. If not found, an error will be raised.

Assigning values

Some variables cannot be set to specific values through code. Only the counter, the source and the destination can be assigned values.

To assign the counter, type any number using the digit keys. If any number is found during excecution, the counter is multiplied by 10 and the digit is added to it. For example, writing 50cc7 will set the counter to 507 despite the two c's between. To reset the counter, simply type z.

The source can be assigned by enclosing text with double quotes ("), while the destination can be set by enclosing text in single quotes ('). 33 supports escape characters, or untypable characters which are represented by the symbol \. For example, typing "\n" will represent a newline.

As an additional property, the mutable list is filled with any command-line arguments at the start of the program.

Alphabetical commands

Symbol Operation Rough Psuedocode (Python)
a Add the counter value to the accumulator value.
a += c
b Sets the destination to the counterth item in the mutable list. (Empty the destination if the counter is out of range) (1-indexed)
d = m[c - 1]
c Swap the values of the accumulator and the counter
a, c = c, a
d Set the accumulator to the floor of the accumulator divided by the counter
a //= c
e Append the source string to the destination string
d += s
f Set the counterth element in the mutable list to the source (1-indexed)
m[c - 1] = s
g Excecute the next command only if the accumulator is greater than 0
if a > 0:
h Excecute the next command only if the accumulator is less than 0
if a < 0:
i Print a linefeed (new line) to STDOUT
print()
j Set the accumulator to the ASCII value of the counterth character in the source (0-indexed)
a = ord(s[c])
k Set the counterth character in the destination to the character with its ASCII value equal to the accumulator (0-indexed)
d[c] = chr(a)
l Get the value at the variable in the general integer memory dictionary whose name equals the source.
a = g[s]
m Subtract the counter value from the accumulator value
a -= c
n Excecute the next command only if the accumulator is 0
if a == 0:
o Print the value of the accumulator to STDOUT
print(a, end = "")
p Print the value of the source string to STDOUT
print(s, end = "")
q Excecute the function whose name equals the source. See Functions
eval(f[s])
r Set the accumulator to its modulus with the counter
a %= c
s Save the accumulator value to the general integer memory, with its name being the destination.
g[d] = a
t Swap the source and the destination
s, d = d, c
u Swap the mutable and backup lists
m, b = b, m
v Concatenate the backup list to the mutable list
m += b
w Set the accumulator to the number of elements in in the mutable list
a = len(m)
x Set the accumulator to its product with the counter
a *= c
y Append the source to the mutable list
m.append(s)
z Nullify the counter
c = 0
G Excecute the next command only if the accumulator is less than or equal to 0
if a <= 0:
H Excecute the next command only if the accumulator is greater than or equal to 0
if a >= 0:
I Set the destination to the next line read from STDIN
d = i
N Excecute the next command only if the accumulator not 0
if a != 0:
O Set the accumulator to the next integer found in STDIN (if not found, set the accumulator to 0)
import re
a = int(re.findall(r'\d+', i)) + 0
P Set the accumulator to the ASCII value of the next character in STDIN
a = ord(i[0])
Z Clear the mutable list
m = []

Symbolical commands

Symbol(s) Operation
0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Multiply the counter by 10 and add the value of the digit. See Assigning values
" Toggle source parsing. See Assigning values
' Toggle destination parsing. See Assigning values
{ Start function parsing. See Functions
} End function parsing.
[ Jump foreward to the corresponding ] if the accumulator is 0 (similar to the [ in brainfuck)
] Jump back to the corresponding [ if the accumulator is not 0 (similar to the ] in brainfuck)
@ Terminates the program before the program finishes.

Examples

Hello World

"Hello, World!"p

The code is easy to understand: It pushes the string "Hello, World!" to the source, then prints it using the p alphacommand.

Truth-machine

 O[on@]

Gets the number from STDIN. Outputs it once, and if the number is not zero, the program continues to print it until the end of time.

99 bottles of beer

99c1[o" bottles of beer on the wall,"pio" bottles of beer.\nTake one down, pass it around,"pimo" bottles of beer on the wall"pii]

External resources