Smasnug 🕳️ABrainFIsHCHIHqFRSI9efuck+-~B2D

From Esolang
Jump to navigation Jump to search

Smasnug 🕳ABrainFIsHCHIHqFRSI9efuck+-~B2D(Also known as Smasnug 🕳ABrainFIsHCHIHqFRSI9ef***+-~B2D, HQ9+brahbrahbrah, HQ9+-~B2D) is an esolang by User:Yoyolin0409. The inspiration came from "HQ9+" and its various enhanced versions.
It is Turing-complete because it can explain brainfuck.

Smasnug 🕳ABrainFIsHCHIHqFRSI9efuck+-~B2D
Designed by User:Yoyolin0409
Appeared in 2025
Computational class Unknown
Reference implementation Unimplemented
Influenced by HQ9+, HQ9++, HQ9+-, HQ9+~, HQ9F+, FHQ9+-, CHIQRSX9+, HQ9+B, HQ9+2D, H9+, FISHQ9+, HI9+, +, Hq9eFuck, BrainfisHQ9+, ACHEQUEUENINETHOUSANDPLUS, AHQ9+-, HQ9~, Smasnug, 🕳️Q9+
File extension(s) .hq4brahbrahbrah

Instructions

Ignore any non-instructional characters, such as spaces, newlines, and other characters. But, instructions consisting of multiple characters must be linked together.
It has an instruction pointer which starts at the first byte of the program, moving east.

  • H: Output"hello, world"
  • Q: Output the program's source code
  • 9: Output the lyrics to "99 Bottles of Beer"
  • +: Increment the memory cell under the pointer
  • ++: Increment the memory cell under the pointer twice, and instantiate an object of a new sub class of the generic super class. Due to the best principles of object hiding, this object cannot be accessed in any way.
  • - behaves differently based on what character(s) it follows:
  1. start of file: Syntax error
  2. H: I/O error
  3. Q: Infinite recurse
  4. 9: Infinite loop
  5. -: Decrement the memory cell under the pointer
  6. +: 1/0
  7. ++: Virtual exception ("which itself is a method of an object of a new subclass of the generic superclass. In line with the best data-hiding principles, there is no way to intercept this exception.")
  8. F: Dereferences a null pointer error
  • If a H is followed by a tilde, it will print out the text of FizzBuzz up to the current value of the memory cell under the pointer.
  • If Q is followed by a tilde, it will run the Truth-machine.
  • If an 9 is followed by a tilde, it will create and run a new Universal Turing machine. In fact, it will output the error "Unable to create" regardless.
  • If a + is followed by a tilde, it will get input from the user and input to the memory cell under the pointer.
  • F: Output FizzBuzz up to the time the memory cell under the pointer got edited.
  • f: Output FizzBuzz up to 100
  • I: Interprets input as program source
  • R: Encrypts input with ROT-13 and input to the memory cell under the pointer
  • S: Sorts input and input to the memory cell under the pointer
  • X1(<Perl>): Randomly adds a number to each letter and runs a Perl
  • X2(<Perl>): Adds 7 to each char then runs as Perl
  • B: read input and execute as a brainfuck program
  • >: Move east
  • <: Move west
  • ^: Move north
  • v: Move south
  • NOQ: Remove "Q"
  • D: Decrement the the memory cell under the pointer
  • s: Square
  • O: Output the memory cell under the pointer
  • K: Terminate
  • Z: Set the memory cell under the pointer to 0
  • i: Output "I can't bel1eve 1t's not qu1ne!"
  • ONLY+: Remove all instructions that are not "+"
  • DT: Output 42
  • ,: Input a character and store it in the cell at the pointer
  • [: Jump past the matching ] if the cell under the pointer is 0
  • ]: Jump back to the matching [ if the cell under the pointer is nonzero
  • h: Output "HELLO MORTAL"
  • q: Output "every possible HQ9000+ program"
  • N: Output the lyrics to "Ascending N Bottles of Beer" (starts with 0 bottles and more bottles are added to the wall)
  • ADD INFINITY!!!!!: Crash
  • A: Output all memory cell's content(Not included 0)
  • P: Output "Porcupine on your head"
  • C[value]: digital root[value] and output
  • b: Output "01101101 01100001 01111000 00100000 01110011 01101011 01110101 01101100 01101100 01101001 01110011 01101000"
  • S: Error named "Bruddyo ain't smart bruh"
  • R: Output "Is the code below this Python?"
  • var[name]=[value]: Creates a variable
  • input[question]=[name]: Input a variable
  • print[name]: Outputs a variable
  • bruh[name]: Input [name] to the cell under the pointer
  • Y: Output "Yes, is it"
  • U: Output "dragon appears out of thin air"
  • T[value]: Output value
  • CL: Delete all instructions
  • =: Output all variable's content
  • RE: Set variable to 0
  • IP: Output "your IP"
  • SM: It gives you a confirmation request, If you confirm it, Nothing happend
  • HELP: Output "existing is bonish" or "Know what? I'm confused." or "did you know this on battle with air" or "max skullish bro thought this was a joke"
  • d: Outputs "was unreasonable"
  • 2: Outputs the memory cell #2's content
  • TO: Puts 1 character input(in decimal) in memory cell #3
  • /: Divides memory cell #1 by memory cell #2 and puts it in memory cell #3
  • {: Sets execution direction to right
  • }: Sets execution direction to left
  • ♪[name]: Plays note [memory cell #1] for 0.02*[name] seconds
  • 13: Swaps memory cell #1 and memory cell #3
  • 23: Swaps memory cell #2 and memory cell #3
  • ⚠️: Reverse input and return it
  • : Output input
  • (code): Repeat code forever
  • [value or name](code): Repeat code [value or name] times
  • IF[num]=[value]: If memory cell #[num]=[value]...
  • __SP__: space
  • #[brahbrahbrah]: Notes
  • HIDE: Hide the next Output
  • IN: Input Output
  • ELIF: elif

Example

hello, world

H

Hello, world!

THello,__SP__world!

99 bottles of beer

9

Quine

Q

Cat

Digital root calculator

inputType__SP__your__SP__number=a ca

ROT13 encoder

R

Truth-machine

Q~

FizzBuzz

+~F~

Infinite loop

(Thi )

Palindrome

ez#ze

Interpreter

Python(WIP)

import random
import sys  # Used for K command to terminate the program

# ===== Custom Error Classes =====
I_O_Error = type("I/O Error", (Exception,), {})
InfRecurse = type("InfRecurse", (Exception,), {})
InfLoop = type("InfLoop", (Exception,), {})
VirtualError = type("VirtualError", (Exception,), {})
NullPointerError = type("NullPointerError", (Exception,), {})
TruthMachineError = type("TruthMachineError", (Exception,), {})
CreateTuringMachineError = type("CreateTuringMachineError", (Exception,), {})

def run_script(file_path, allowed_ext=".hq4brahbrahbrah"):
    if not file_path.endswith(allowed_ext):
        raise ValueError(f"Only {allowed_ext} files are allowed")

    # Read file
    with open(file_path, "r", encoding="utf-8") as f:
        lines = f.read().splitlines()
        full_content = "\n".join(lines)

    # Beginning - raise error if starts with "-"
    if full_content.startswith("-"):
        raise SyntaxError("test")

    # ===== 2D Brainfuck Tape and Counters =====
    ROWS = 500
    COLS = 500
    tape = [[0 for _ in range(COLS)] for _ in range(ROWS)]
    counters = [[0 for _ in range(COLS)] for _ in range(ROWS)]
    row_ptr = 0
    col_ptr = 0
    loop_stack = []  # 2D Brainfuck loop stack

    # ===== Global object counter =====
    objects = 0
    objects_used = False

    # ===== 1D Brainfuck Tape =====
    BF_TAPE_LENGTH = 50000
    bf_tape = [0] * BF_TAPE_LENGTH
    bf_ptr = 0
    
    noq_active = False
    # ===== 99 Bottles of Beer =====
    def print_99_bottles():
        for n in range(99, 0, -1):
            if n > 1:
                print(f"{n} bottles of beer on the wall,")
                print(f"{n} bottles of beer.")
                print("Take one down, pass it around,")
                next_b = n - 1
                if next_b == 1:
                    print(f"{next_b} bottle of beer on the wall.\n")
                else:
                    print(f"{next_b} bottles of beer on the wall.\n")
            else:
                print(f"{n} bottle of beer on the wall,")
                print(f"{n} bottle of beer.")
                print("Take one down, pass it around,")
                print("No bottles of beer on the wall.\n")
        print("No bottles of beer on the wall,")
        print("No bottles of beer.")
        print("Go to the store, buy some more,")
        print("99 bottles of beer on the wall.\n")

    # ===== Execute single HQ9+ command =====
    def run_line(line):
        nonlocal row_ptr, col_ptr, objects, objects_used, bf_ptr, bf_tape, noq_active, loop_stack

        i = 0
        while i < len(line):
            ch = line[i]

            # ===== H series =====
            if ch == "H":
                if i + 1 < len(line):
                    if line[i + 1] == "-":
                        raise I_O_Error("test")
                    elif line[i + 1] == "~":
                        n = tape[row_ptr][col_ptr]
                        for x in range(n + 1):
                            if x % 15 == 0 and x != 0:
                                print("FizzBuzz")
                            elif x % 3 == 0 and x != 0:
                                print("Fizz")
                            elif x % 5 == 0 and x != 0:
                                print("Buzz")
                            else:
                                print(x)
                        i += 1
                    else:
                        print("Hello, world!")
                else:
                    print("Hello, world!")

            # ===== NOQ command =====
            elif line[i:i+3] == "NOQ":
                noq_active = True
                i += 2  # Skip NOQ

            # ===== Q series =====
            elif ch == "Q":
               if noq_active:
                   pass  # Q series disabled
               else:
                if i + 1 < len(line):
                    if line[i + 1] == "-":
                        raise InfRecurse("test")
                    elif line[i + 1] == "~":
                        val = input("Enter 0 or 1: ")
                        try:
                            val_int = int(val)
                        except ValueError:
                            raise TruthMachineError("Invalid input")
                        if val_int == 0:
                            print(0)
                        elif val_int == 1:
                            while True:
                                print(1)
                        else:
                            raise TruthMachineError("Invalid input")
                        i += 1
                    else:
                        print(full_content)
                else:
                    print(full_content)

            # ===== 9 series =====
            elif ch == "9":
                if i + 1 < len(line):
                    if line[i + 1] == "-":
                        raise InfLoop("test")
                    elif line[i + 1] == "~":
                        raise CreateTuringMachineError("Unable to create")
                    else:
                        print_99_bottles()
                else:
                    print_99_bottles()

            # ===== F series =====
            elif ch == "F":
                if i + 1 < len(line) and line[i + 1] == "-":
                    raise NullPointerError("test")
                else:
                    n = counters[row_ptr][col_ptr]
                    for x in range(n + 1):
                        if x % 15 == 0 and x != 0:
                            print("FizzBuzz")
                        elif x % 3 == 0 and x != 0:
                            print("Fizz")
                        elif x % 5 == 0 and x != 0:
                            print("Buzz")
                        else:
                            print(x)

            # ===== + series =====
            elif ch == "+":
                if i + 2 < len(line) and line[i + 1] == "+" and line[i + 2] == "-":
                    raise VirtualError("???")
                elif i + 1 < len(line) and line[i + 1] == "-":
                    raise ZeroDivisionError("test")
                elif i + 1 < len(line) and line[i + 1] == "+":
                    tape[row_ptr][col_ptr] += 2
                    counters[row_ptr][col_ptr] += 1
                    objects += 1
                    objects_used = True
                    i += 1
                elif i + 1 < len(line) and line[i + 1] == "~":
                    val = input(f"Enter integer for tape[{row_ptr},{col_ptr}]: ")
                    try:
                        tape[row_ptr][col_ptr] = int(val)
                    except ValueError:
                        raise ValueError("Input must be an integer")
                    counters[row_ptr][col_ptr] += 1
                    i += 1
                else:
                    tape[row_ptr][col_ptr] += 1
                    counters[row_ptr][col_ptr] += 1

            # ===== -- decrease cell =====
            elif ch == "-":
                if i + 1 < len(line) and line[i + 1] == "-":
                    tape[row_ptr][col_ptr] -= 1
                    counters[row_ptr][col_ptr] += 1
                    i += 1

            # ===== I command =====
            elif ch == "I":
                user_code = input("Enter a line of Smasnug 🕳️ABrainFIsHCHIHqFRSI9efuck+-~B2D code: ")
                if user_code.strip() == "I":
                    run_script(file_path)
                else:
                    run_line(user_code)

            # ===== R command =====
            elif ch == "R":
                user_input = input("Enter text for ROT-13 encryption: ")
                def rot13(text):
                    result = []
                    for c in text:
                        if 'a' <= c <= 'z':
                            result.append(chr((ord(c) - ord('a') + 13) % 26 + ord('a')))
                        elif 'A' <= c <= 'Z':
                            result.append(chr((ord(c) - ord('A') + 13) % 26 + ord('A')))
                        else:
                            result.append(c)
                    return ''.join(result)
                print(rot13(user_input))

            # ===== S command =====
            elif ch == "S":
                user_input = input("Enter a number: ")
                try:
                    num = float(user_input)
                except ValueError:
                    raise ValueError("Input must be a number")
                negative = num < 0
                num_str = str(abs(num))
                if '.' in num_str:
                    integer_part, decimal_part = num_str.split('.')
                    integer_sorted = ''.join(sorted(integer_part))
                    decimal_sorted = ''.join(sorted(decimal_part))
                    sorted_num_str = integer_sorted + '.' + decimal_sorted
                else:
                    sorted_num_str = ''.join(sorted(num_str))
                if negative:
                    sorted_num_str = '-' + sorted_num_str
                try:
                    tape[row_ptr][col_ptr] = float(sorted_num_str) if '.' in sorted_num_str else int(sorted_num_str)
                except ValueError:
                    raise ValueError("Failed to convert sorted number")
                counters[row_ptr][col_ptr] += 1

            # ===== X1(<Perl>) command =====
            elif line[i:i+2] == "X1":
                start = line.find("(", i)
                end = line.find(")", start)
                if start == -1 or end == -1:
                    raise SyntaxError("Invalid X1 syntax")
                perl_content = line[start+1:end]

                for r in range(ROWS):
                    for c in range(COLS):
                        if tape[r][c] != 0:
                            tape[r][c] += random.randint(0, 100)
                            counters[r][c] += 1

                raise type("PerlError", (Exception,), {})(f"There is no suitable programming environment to execute {perl_content}")

                i = end + 1

            # ===== X2(<Perl>) command =====
            elif line[i:i+2] == "X2":
                start = line.find("(", i)
                end = line.find(")", start)
                if start == -1 or end == -1:
                    raise SyntaxError("Invalid X2 syntax")
                perl_content = line[start+1:end]

                for r in range(ROWS):
                    for c in range(COLS):
                        if tape[r][c] != 0:
                            tape[r][c] += 7
                            counters[r][c] += 1

                raise type("PerlError", (Exception,), {})(f"There is no suitable programming environment to execute {perl_content}")

                i = end + 1

            # ===== B command (1D Brainfuck) =====
            elif ch == "B":
                bf_code = input("Enter a Brainfuck program: ")

                # Validate Brainfuck program
                for c in bf_code:
                    if c not in "<>+-.,[]":
                        raise type("brainfuckError", (Exception,), {})("Not a brainfuck program")

                bf_ptr = 0
                bf_tape = [0] * BF_TAPE_LENGTH
                code_ptr = 0
                code_len = len(bf_code)
                loop_stack_bf = []

                while code_ptr < code_len:
                    cmd = bf_code[code_ptr]
                    if cmd == ">":
                        bf_ptr = (bf_ptr + 1) % BF_TAPE_LENGTH
                    elif cmd == "<":
                        bf_ptr = (bf_ptr - 1) % BF_TAPE_LENGTH
                    elif cmd == "+":
                        bf_tape[bf_ptr] = (bf_tape[bf_ptr] + 1) % 256
                    elif cmd == "-":
                        bf_tape[bf_ptr] = (bf_tape[bf_ptr] - 1) % 256
                    elif cmd == ".":
                        print(chr(bf_tape[bf_ptr]), end="")
                    elif cmd == ",":
                        user_inp = input("Input one char: ")
                        bf_tape[bf_ptr] = ord(user_inp[0]) if user_inp else 0
                    elif cmd == "[":
                        if bf_tape[bf_ptr] == 0:
                            open_brackets = 1
                            while open_brackets > 0:
                                code_ptr += 1
                                if code_ptr >= code_len:
                                    raise type("brainfuckError", (Exception,), {})("Not a brainfuck program")
                                if bf_code[code_ptr] == "[":
                                    open_brackets += 1
                                elif bf_code[code_ptr] == "]":
                                    open_brackets -= 1
                        else:
                            loop_stack_bf.append(code_ptr)
                    elif cmd == "]":
                        if bf_tape[bf_ptr] != 0:
                            if not loop_stack_bf:
                                raise type("brainfuckError", (Exception,), {})("Not a brainfuck program")
                            code_ptr = loop_stack_bf[-1] - 1
                        else:
                            loop_stack_bf.pop()
                    code_ptr += 1

            # ===== 2D Tape pointer movement =====
            elif ch == ">":
                col_ptr = (col_ptr + 1) % COLS
            elif ch == "<":
                col_ptr = (col_ptr - 1) % COLS
            elif ch == "^":
                row_ptr = (row_ptr - 1) % ROWS
            elif ch == "v":
                row_ptr = (row_ptr + 1) % ROWS

            # ===== D command =====
            elif ch == "D":
                tape[row_ptr][col_ptr] -= 1
                counters[row_ptr][col_ptr] += 1

            # ===== s command =====
            elif ch == "s":
                tape[row_ptr][col_ptr] **= 2
                counters[row_ptr][col_ptr] += 1

            # ===== O command =====
            elif ch == "O":
                print(tape[row_ptr][col_ptr])

            # ===== K command =====
            elif ch == "K":
                sys.exit()

            # ===== Z command =====
            elif ch == "Z":
                tape[row_ptr][col_ptr] = 0
                counters[row_ptr][col_ptr] += 1

            # ===== i command =====
            elif ch == "i":
                print("I can't bel1eve 1t's not qu1ne!")

            # ===== ONLY+ command =====
            elif line[i:i+5] == "ONLY+":
                sys.exit()
                i += 4  # Skip ONLY+

            # ===== DT command =====
            elif line[i:i+2] == "DT":
                print(42)
                i += 1  # Skip D and T

            # ===== 2D Tape Brainfuck commands =====
            elif ch in ",[]":
                if ch == ",":
                    user_inp = input("Input one char: ")
                    tape[row_ptr][col_ptr] = ord(user_inp[0]) if user_inp else 0
                    counters[row_ptr][col_ptr] += 1
                elif ch == "[":
                    if tape[row_ptr][col_ptr] == 0:
                        # Jump to matching "]"
                        open_brackets = 1
                        while open_brackets > 0:
                            i += 1
                            if i >= len(line):
                                raise SyntaxError("Unmatched '['")
                            if line[i] == "[":
                                open_brackets += 1
                            elif line[i] == "]":
                                open_brackets -= 1
                    else:
                        # Push position to loop stack
                        loop_stack.append(i)
                elif ch == "]":
                    if tape[row_ptr][col_ptr] != 0:
                        if not loop_stack:
                            raise SyntaxError("Unmatched ']'")
                        i = loop_stack[-1] - 1
                    else:
                        loop_stack.pop()

            i += 1

    # ===== Execute entire file =====
    for line in lines:
        run_line(line)

    # ===== Output objects if used =====
    if objects_used:
        print(f"objects:{objects}")

# ===== Run file =====
run_script("<file_path>")