SETANDCOUNT

From Esolang
Jump to navigation Jump to search

Introduction

SETANDCOUNT (SAC for short) is an list-based esolang whose programmes consist of digits0-9 & spaces .

Data Format

The data are formed in a sorted integer list with no duplicates. After each operation, SAC discards duplicates and then sorts the integers.

[2,3,1,1] -> [1,2,3]

Operations

The code is a string consisting of digits0-9 & spaces . It's read char-by-char.



  • (space): Ignored. (This feature is useful in jumping.)

  • 1-6: Increase the first 1-6 elements of data by 1 if data's length is equal or greater than 1-6. Otherwise, increase all elements and then, push 1 into data.

P.S.: Data is then sorted and unified.


  • 7: Input a number x, overwrite the first element of data with x. (If empty, push x)

P.S.: Data is then sorted and unified.


  • 8: Output the last number of data. (If empty, output 0)

  • 9[1-9 ]*0: Jump. The middle part represents an address. (Spaces are ignored and the address starts from 0.)

If the previous operation generated a duplicate/duplicates, jump to the address. Otherwise, jump to the end of the operation (0).


  • 0 (outsides 9...0): (The operation is still in consideration) Jump to the position item of the number following 0 and set this item to the opposite of the second number following 0.

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 

Online Interpreter:Here

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.