SETANDCOUNT

From Esolang
Jump to navigation Jump to search

Introduction & Syntax

SETANDCOUNT (SAC for short) is a language for storing in an ordered list.There is SAC syntax:

  • Numbers 1~6:Suppose that the first n values are added by one to form S(n),O(S(n)) represents the original value of the number of operations currently performed. The numbers 1-6 represent S(1)~S(6).When O(S(n)) (n represents any number from 1 to 6) is a non-positive number,The running result is equivalent to S(n+(-O(S(n))).

Tip: When the number in S() is greater than the number of elements in the list, there is an extra 1 in the last list.


  • Number 0:Jump to the position item of the number following 0 and set this item to the opposite of the second number following 0.

  • Number 9:If the list does not shrink before the instruction, the code jumps to the number represented by the number between the 9 and the first 0 after the 9.

  • Number 7 and Number 8:Input and Output.Store to the first unit and last unit. (stored in digital form)


I don't think the operation when the item is equal to 0 is really useful, so I may update its usage later.

Some examples

Calculation 8-2+1:

11111122329110

infinite loop:

910

Cat program:

78

Truth machine(Input 0 or 1 => 1 or 2)(and if you input 2 it will puts 3):

7218940

PlusOrOutput but can't reset to 0 ,it will increment 1 when it outputs, its accelerator starts 2.(1 is + and 2 is .)

127319130930191308930

Interpreter

The interpreter written in Python follows.

l=[];pointer=0;cd="7218940";cp=0;c=1#The content of the variable cd is the code
while cp<len(cd):
    i=cd[cp];o=l[:]
    if i in "123456":
        f=[]
        t=(int(i),0) if int(i)<=len(l) else (len(l),1)
        for k in range(t[0]):
            if l[k]>0:l[k]+=1
            elif l[k]<0:f.append(str(-l[k]))    
        if t[1]:l.append(1)
        if len(f)>0:cd="".join(list(cd[:cp])+f+list(cd[cp:]))        
        pointer=0;l=list(set(l))
        l.sort()
        if len(o)>len(l):c=0
    if i=="0":
        pointer=int(cd[cp+1]);l[pointer]=-int(cd[cp+2])
        cp+=2
        l.sort()
        if len(o)>len(l):c=0
    if i=="9":
        tmp=cp+cd[cp:].index("0")
        if c:cp=int(cd[cp+1:cp+cd[cp:].index("0")])-2
        else:cp=tmp;c=1
    if i=="7":
        if len(l)>0:l[0]=ord(input()[0])
        else:l.append(ord(input()[0]))
    if i=="8":
        print(chr(l[-1]))   
    cp+=1 
#print(l)

Deobfuscation attempt:

tape = []
code = "7218940"
code_pointer = 0
havent_shrank = 1

while code_pointer < len(code):
    instruction = int(code[code_pointer])
    if instruction in [1, 2, 3, 4, 5, 6]:
        normalized = []
        # increment all positive values on the tape less than the instruction
        # normalize negatives
        for k in range(min(instruction, len(tape))):
            if tape[k] > 0:
                tape[k] += 1
            elif tape[k] < 0:
                normalized.append(str(-tape[k]))    
        if len(tape) <= instruction:
            tape.append(1)
        # if there were negative values, insert them normalized as code at the code pointer
        if len(normalized) > 0:
            code = code[:code_pointer] + "".join(normalized) + code[code_pointer:]
        prior_len = len(tape)
        # remove duplicates and sort
        tape = list(set(tape))
        tape.sort()
        # clear nonshrink flag if necessary
        if prior_len > len(tape):
            havent_shrank = 0
    elif instruction == 0:
        pointer = int(code[code_pointer + 1])
        tape[pointer] = -int(code[code_pointer + 2])
        code_pointer += 2
        tape.sort()
    elif instruction == 9:
        next_zero = code_pointer + code.index("0", code_pointer)
        if havent_shrank:
            # this should be erroneous
            code_pointer = int(code[code_pointer + 1:next_zero]) - 2
        else:
            code_pointer = next_zero
            havent_shrank = 1
    # input
    elif instruction == 7:
        if len(tape) > 0:
            tape[0] = ord(input()[0])
        else:
            tape.append(ord(input()[0]))
    # output
    elif instruction == 8:
        print(chr(tape[-1]))   
    code_pointer += 1 


Something I wanted to say

This esolang is inspired by Python's set type. It's stored roughly as a set in Python. However, sometimes you can't sort in the correct order. (For example, {7,8,9} will be converted to {8,9,7} and so on) .so I'm abandoning the set and using an ordered list store.It's a completely helpless move.


Good Luck.