We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

ShiftAleph

From Esolang
Jump to navigation Jump to search

ShiftAleph, created by User:Broxol, is the successor of ShiftAlpha, created by the same person.

INTRODUCTION

ShiftAleph was not designed to be easy. It is based off of the 15 puzzle, the sliding block puzzle. In order to run functions, you must slide whichever block you want to run into the bottom right corner.

ShiftAleph is an evolution of the previously mentioned ShiftAlpha. ShiftAlpha is not turing complete and was a 2x2 grid, a demonstration of what ShiftAleph would come to be. ShiftAleph has a 4x4 grid, complete with 15 different commands.

ShiftAleph is easily the hardest programming language to program in that I’ve made.

FUNCTIONS

ShiftAleph has many functions, but you can only use 4 within programming.

Shift Functions

Shift Functions
Syntax What it does
ABCD1234 ^v>< Pushes object at the coordinates in the direction given. (e.g. A1 v pushes whatever is on A1 down)
# Calls the function on the bottom-right corner
[…] Conditional loop. Checks the top item, if it’s 0, it breaks the loop
r Resets the grid
/ Prematurely ends the program and gives you useful data

Grid Functions

Grid Functions
Name Value Function
print 0 prints top item of the stack
input 1 appends user-input to top of the stack
stack 2 sets mode to stacking mode. In this mode, any usage of # on a function will append its value to the top item of the stack. Use # on None to cancel it.
add 3 takes top two items of stack and adds them, puts sum on top of stack
sub 4 subtracts top two items of stack
mul 5 multiplies top two items of stack
div 6 divides top two items of stack (this is a floor divide so no floats)
mod 7 gives mod of top two items of stack
reach 8 takes top item of stack and puts the item at -said_item on top of stack
copy 9 duplicates top item of stack
if 10 pops the top 3 items. The first two items are checked under the condition of the 3rd (0 - ==, 1 - >, 2 - <, 3 - >=, 4 - <=, 5 - !=), returns either 0 or 1 and puts it on top of stack
not 11 flips top item of stack (only works on 0s and 1s)
and 12 performs AND operation on top 2 items of stack
or 13 performs OR operation on top 2 items of stack
xor 14 performs XOR operation on top 2 items of stack
None no value Does nothing, except if stacking, then it cancels the stacking

EXAMPLES

CAT program:

C4 v # C4 ^ D3 > #

Infinite CAT program:

C4 v C3 > D3 ^ D4 < C4 v # # D4 ^ # [r C4 v # D4 ^ D3 > #]

INTERPRETER

import copy

grid = [["not","and","or","xor"],["reach","mul","div","mod"],["copy","add","stack","input"],["if","sub","print",None]]
print(grid)
static_grid = copy.deepcopy(grid)
stack = []
#ABCD 1234

code = "Insert code here..."
code = list(code)

stack_dict = {"print":"0","input":"1","stack":"2","add":"3","sub":"4","mul":"5","div":"6","mod":"7","reach":"8","copy":"9","if":"10","not":"11","and":"12","or":"13","xor":"14"}
letter_value = {"A":0,"B":1,"C":2,"D":3}
is_stacking = False

for item in code:
    if item == " ":
        code.pop(code.index(item))

print(code)

i = 0
while i < len(code):
    if code[i] == "/":
        print(grid)
        print(stack)
        print(is_stacking)
        break
    elif code[i] == "r":
        grid = copy.deepcopy(static_grid)
        i += 1
    elif code[i] == "#":
        if is_stacking == True:
            if grid[3][3] == None:
                is_stacking = False
                i += 1
            else:
                stack[-1] = str(stack[-1]) + stack_dict[grid[3][3]]
                i += 1
        else:
            if grid[3][3] == "print":
                print(stack.pop())
            elif grid[3][3] == "input":
                stack.append(str(input()))
            elif grid[3][3] == "stack":
                stack.append('')
                is_stacking = True
            elif grid[3][3] == "add":
                #REMEMBER HEXIDECIMAL
                val1 = int(stack.pop())
                val2 = int(stack.pop())
                stack.append(str(val1 + val2))
            elif grid[3][3] == "sub":
                #REMEMBER HEXIDECIMAL
                val1 = int(stack.pop())
                val2 = int(stack.pop())
                stack.append(str(val1 - val2))
            elif grid[3][3] == "mul":
                #REMEMBER HEXIDECIMAL
                val1 = int(stack.pop())
                val2 = int(stack.pop())
                stack.append(str(val1 * val2))
            elif grid[3][3] == "div":
                #REMEMBER HEXIDECIMAL
                val1 = int(stack.pop())
                val2 = int(stack.pop())
                stack.append(str(val1 // val2))
            elif grid[3][3] == "mod":
                #REMEMBER HEXIDECIMAL
                val1 = int(stack.pop())
                val2 = int(stack.pop())
                stack.append(str(val1 % val2))
            elif grid[3][3] == "reach":
                reach = stack.pop(-int(stack.pop()))
                stack.append(reach)
            elif grid[3][3] == "copy":
                stack.append(stack[-1])
            elif grid[3][3] == "if":
                val1 = stack.pop()
                val2 = stack.pop()
                check = stack.pop()
                if check == "0":
                    if val1 == val2:
                        stack.append("1")
                    else:
                        stack.append("0")
                elif check == "1":
                    if val1 > val2:
                        stack.append("1")
                    else:
                        stack.append("0")
                elif check == "2":
                    if val1 < val2:
                        stack.append("1")
                    else:
                        stack.append("0")
                elif check == "3":
                    if val1 >= val2:
                        stack.append("1")
                    else:
                        stack.append("0")
                elif check == "4":
                    if val1 <= val2:
                        stack.append("1")
                    else:
                        stack.append("0")
                elif check == "5":
                    if val1 != val2:
                        stack.append("1")
                    else:
                        stack.append("0")
            elif grid[3][3] == "not":
                if stack[-1] == "1":
                    stack[-1] = "0"
                elif stack[-1] == "0":
                    stack[-1] = "1"
                else:
                    assert 1 == 2, f"BitError: wtf man {stack[-1]} is not 1 or 0"
            elif grid[3][3] == "and":
                bit1 = stack.pop()
                bit2 = stack.pop()
                if bit1 == "1":
                    if bit2 == "1":
                        stack.append("1")
                    else:
                        stack.append("0")
                else:
                    stack.append("0")
            elif grid[3][3] == "or":
                bit1 = stack.pop()
                bit2 = stack.pop()
                if bit1 == "0":
                    if bit2 == "1":
                        stack.append("1")
                    else:
                        stack.append("0")
                else:
                    stack.append("1")
            elif grid[3][3] == "xor":
                bit1 = stack.pop()
                bit2 = stack.pop()
                if bit1 == "1":
                    if bit2 == "1":
                        stack.append("0")
                    else:
                        stack.append("1")
                else:
                    if bit2 == "0":
                        stack.append("0")
                    else:
                        stack.append("1")
            i += 1
    elif code[i] in "ABCD": 
        pushA = letter_value[code[i]]
        push1 = int(code[i + 1]) - 1
        i += 2
        if code[i] == "v":
            pushB = pushA + 1
            assert grid[pushB][push1] == None, f"item {grid[pushB][push1]} was not None object"
            grid[pushB][push1], grid[pushA][push1] = grid[pushA][push1], grid[pushB][push1]
        elif code[i] == "^":
            pushB = pushA - 1
            assert grid[pushB][push1] == None, f"item {grid[pushB][push1]} was not None object"
            grid[pushB][push1], grid[pushA][push1] = grid[pushA][push1], grid[pushB][push1]
        elif code[i] == ">":
            push2 = push1 + 1
            assert grid[pushA][push2] == None, f"item {pushA, push2} was not None object"
            grid[pushA][push2], grid[pushA][push1] = grid[pushA][push1], grid[pushA][push2]
        elif code[i] == "<":
            push2 = push1 - 1
            assert grid[pushA][push2] == None, f"item {grid[pushA][push2]} was not None object"
            grid[pushA][push2], grid[pushA][push1] = grid[pushA][push1], grid[pushA][push2]
        i += 1
    elif code[i] == "]":
        if stack[-1] == "0":
            i += 1
        else:
            while code[i] != "[":
                i -= 1
    else:
        i += 1