12345678

From Esolang
Jump to navigation Jump to search

12345678 is an esolang invented by User:None1 when he noticed that he didn't invent many Chinese brainfuck equivalents, also because he encountered one of his own brainfuck equivalents by random page.

Commands

The commands:

一二三四五六七八

represent:

+-<>,.[]

in brainfuck.

Example programs

Cat program

五七六五八

Hello World

一一一一一一一一七四一一一一七四一一四一一一四一一一四一三三三三二八四一四一四二四四一七三八三二八四四六四二二二六一一 一一一一一六六一一一六四四六三二六三六一一一六二二二二二二六二二二二二二二二六四四一六四一一六

Kolakoski sequence

一一一一一一一七四一一一一一一一三二八四六一六六二六六七二八 ; Print out "12211"
一四四四四一一四四四四一一四四四四一四一四四四一四四一三三三三三三三三三三三三三三三三三三三 ; Store 1 2 2 1 1
                                                                                             ;            s^ f^
一七 ; Infinite loop
    四四二七一四四四四二八一 ; Go to the slow pointer
    三七
        四四二七一四四四四二八一 ; Go to the fast pointer
        四四七四四四四八一一一 ; Set top value to 3
        三三二七一三三三三二八一 ; Go back to the fast pointer
        三三七四四四一四七四四四四八三三三三二三三二七一三三三三二八一三三二八 ; Set top value to 3 minus fast pointer value
        四四四七三三三一四四四二八 ; Restore fast pointer value
        三三三七四四四四八三三三一一一一一一七三一一一一一一一一四二八三六 ; Output top value as character
        四一一一一一一七三二二二二二二二二四二八 ; Restore to number
        二七一三三三三二八一三二 ; Decrement slow pointer value
    八
    四四四七三三三一四四四二八 ; Restore slow pointer value
    三二七一四四四四二八一 ; Go to the fast pointer
    七四四七四四四四八三三一三三三三二七一三三三三二八八 ; Move fast pointer to top
    三二七一三三三三二八一七四四四四一三三三三二八 ; Move slow pointer to the next
    四四二七一三三三三二八一 ; Move back to infinite loop flag
八

Interpreter in Python

import sys
def bf(code):
    s=[]
    matches={}
    tape=[0]*1000000
    for i,j in enumerate(code):
        if j=='七':
            s.append(i)
        if j=='八':
            m=s.pop()
            matches[m]=i
            matches[i]=m
    cp=0
    p=0
    while cp<len(code):
        if code[cp]=='一':
            tape[p]=(tape[p]+1)%256
        if code[cp]=='二':
            tape[p]=(tape[p]-1)%256
        if code[cp]=='五':
            c=sys.stdin.read(1)
            tape[p]=(ord(c) if c else 0)%256
        if code[cp]=='六':
            print(chr(tape[p]),end='')
        if code[cp]=='三':
            p-=1
        if code[cp]=='四':
            p+=1
        if code[cp]=='七':
            if not tape[p]:
                cp=matches[cp]
        if code[cp]=='八':
            if tape[p]:
                cp=matches[cp]
        cp+=1
bf(sys.stdin.read())