Tttt

From Esolang
Jump to navigation Jump to search

Tttt is a programming language that employs 10 one-letter instructions (a-j) plus two letters used for comments. Data is stored in an infinite tape of integer cells.

Instructions

The tape is infinite in both directions, and all cells are initialized to 0. The data pointer initially points to some cell.

Letter Action
a Increment current cell by 2.
b Decrement current cell by 1.
c Move data pointer right by 1.
d Move data pointer left by 2.
e Prints the current cell's value as an ASCII character. The original specification does not specify what happens for non-ASCII values.
f Prints the current cell's value as an integer.
g Prints a newline.
h Gets an ASCII character as input, stores the character code in the current cell.
i Enters loop if current cell is nonzero; else skips to matching "j."
j Exits loop if current cell is zero; else jumps to matching "i."

Additionally, anything between a "k" and an "l" is treated as a comment.

Examples

Hello, World!

Multiple lines:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaeabaaaaaaaaaaaaaaeabaaae
eabaebbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbebbbbbbbbbbbbeabaa
aaaaaaaaaaaaaaaaaaaaaaaaaeaaaa
aaaaaaaaeabaebbbbbbebbbbbbbbeb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbe

One line:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaeabaaaaaaaaaaaaaaeabaaaeeabaebbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbebbbbbbbbbbbbeabaaaaaaaaaaaaaaaaaaaaaaaaaaaeaaaaaaaaaaaaeabaebbbbbbebbbbbbbbebbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbe

Truth-machine

This shorter truth-machine requires an input of 0 before the actual input of 0 or 1.

hchdcicbdcbjcifjf

This longer truth-machine only requires the user to input 0 or 1, and not anything beforehand.

aaaicaaaacdbjhcibcdbcjcdifjf

Implementations

This is an implementation in Python which works with the examples above. However, it is not the official implementation. Unless I'm misunderstanding the program, the data pointer would loop instead of being unbounded, but this contradicts the tape of cells being infinite as described in the documentation. Additionally, it would make "c" and "d" identical. This is confusing, as the author of the program is also the author of the language.

def run_tttt(data: str) -> None:
    code = list(data)
    variables = [0, 0, 0]
    pointer = 0
    which_var = 0

    while pointer < len(code):
        if 'a' == code[pointer]:
            variables[which_var] += 2
        elif 'b' == code[pointer]:
            variables[which_var] -= 1
        elif 'c' == code[pointer]:
            which_var += 1
        elif 'd' == code[pointer]:
            which_var -= 2
        elif 'e' == code[pointer]:
            print(chr(variables[which_var]), end="")
        elif 'f' == code[pointer]:
            print(variables[which_var], end="")
        elif 'g' == code[pointer]:
            print("\n", end="")
        elif 'h' == code[pointer]:
            variables[which_var] = ord(input())
        elif 'i' == code[pointer]:
            if variables[which_var] == 0:
                while code[pointer] != 'j':
                    if code[pointer] == 'k':
                        pointer += code[pointer:].index('l')
                    pointer += 1
        elif 'j' == code[pointer]:
            if variables[which_var] != 0:
                while code[pointer] != 'i':
                    if code[pointer] == 'l':
                        while code[pointer] != 'k':
                            pointer -= 1
                    pointer -= 1
                pointer -= 1
        elif 'k' == code[pointer]:
            pointer += code[pointer:].index('l')
        pointer += 1