Mariofuck

From Esolang
Jump to navigation Jump to search

Mariofuck is a esolang made by Mihai Popa. It's Brainfuck, but you only use 1-letter names of Nintendo characters instead of symbols to make programs.

Table

Command Meaning (in full name) Brainfuck equivalent Description
M Mario > Move the pointer to the right
L Luigi < Move the pointer to the left
Y Yoshi + Increment the memory cell at the pointer
C Captain Toad - Decrement the memory cell at the pointer
K Lakitu . Output the character signified by the cell at the pointer
T Toad , Input a character and store it in the cell at the pointer
D Toadette [ Jump past the matching B if the cell at the pointer is 0
B Blue Toad ] Jump back to the matching D if the cell at the pointer is nonzero

Everything other than "M","L","Y","C","K","T","D","B" and is a comment and it's ignored. But if you comment with these, it's executed as a command and it's a error.

Examples

Hello, World!

YYYYYYYYDMYYYYYYYYLCBMYYYYYYYYKMYYYYYYYYDMYYYYYYYYYYYYLCBMYYYYYKYYYYYYYKKYYYKMYYYYYYYYDMYYYYYLCBMYYYYKCCCCCCCCCCCCKLLLLYYYYYYYYYYYYYYYKMMKYYYKCCCCCCKCCCCCCCCKMMYK

Rickrolling, by printing all the lyrics of "Never Gonna Give You Up"

Too long. See here: Mariofuck/Rickroll

99 Bottles Of Beer

Quite long. See here: Mariofuck/99 Bottles Of Beer

Implementer

Python

Version 1 (forked from ChatGPT), longer

Note: edited by myself. See the Numberfuck interpreter, coded by ChatGPT. Still is optimized for everything, including printing the full lyrics of the song Never Gonna Give You Up.

def interpret():
    code = input("Enter Mariofuck code: ")
    memory = [0] * 30000
    pointer = 0
    output_string = ""
    code_length = len(code)
    code_pointer = 0

    loop_stack = []

    commands = {
        'M': lambda: nonlocal_pointer('+'),
        'L': lambda: nonlocal_pointer('-'),
        'Y': lambda: increment_memory(),
        'C': lambda: decrement_memory(),
        'K': lambda: output_to_string(),
        'T': lambda: take_input(),
        'D': lambda: start_loop(),
        'B': lambda: end_loop()
    }

    def nonlocal_pointer(op):
        nonlocal pointer
        if op == '+':
            pointer += 1
        else:
            pointer -= 1

    def increment_memory():
        nonlocal memory, pointer
        memory[pointer] = (memory[pointer] + 1) % 256

    def decrement_memory():
        nonlocal memory, pointer
        memory[pointer] = (memory[pointer] - 1) % 256

    def output_to_string():
        nonlocal memory, pointer, output_string
        output_string += chr(memory[pointer])

    def take_input():
        nonlocal memory, pointer
        user_input = input("Enter input (1 character): ")
        memory[pointer] = ord(user_input[0])

    def start_loop():
        nonlocal memory, pointer, code_pointer, loop_stack
        if memory[pointer] == 0:
            count = 1
            while count != 0 and code_pointer < code_length - 1:
                code_pointer += 1
                if code[code_pointer] == 'D':
                    count += 1
                elif code[code_pointer] == 'B':
                    count -= 1
        else:
            loop_stack.append(code_pointer)

    def end_loop():
        nonlocal code_pointer, loop_stack
        if memory[pointer] != 0:
            code_pointer = loop_stack[-1]
        else:
            loop_stack.pop()

    while code_pointer < code_length:
        command = code[code_pointer]
        if command in commands:
            commands[command]()
        code_pointer += 1

    print("Output:", output_string)

interpret()

Version 2 (created by PrySigneToFry‎), shorter

import sys
def interpretion(code):
    s=[]
    matches={}
    tape=[0]*1000000
    for i,j in enumerate(code):
        if j=='B':
           s.append(i)
        if j=='D':
            m=s.pop()
            matches[m]=i
            matches[i]=m
    cp=0
    p=0
    while cp<len(code):
        if code[cp]=='Y':
            tape[p]=(tape[p]+1)%256
        if code[cp]=='C':
            tape[p]=(tape[p]-1)%256
        if code[cp]=='K':
            c=sys.stdin.read(1)
            tape[p]=(ord(c) if c else 0)%256
        if code[cp]=='T':
            print(chr(tape[p]),end=)
        if code[cp]=='M':
            p-=1
        if code[cp]=='L':
            p+=1
        if code[cp]=='B':
            if not tape[p]:
                cp=matches[cp]
        if code[cp]=='D':
            if tape[p]:
                cp=matches[cp]
        cp+=1
interpretion(sys.stdin.read())

Computational class

Mariofuck is turing-complete because Brainfuck and Numberfuck are also turing-complete!

See also