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.

Trigbf/improved

From Esolang
Jump to navigation Jump to search
Back to Trigbf

Trigbf improved is an esolang invented by User:None1 based on Trigbf7. It's basically the same as Trigbf7, except for one small change.

Difference from Trigbf

  • [CODE]: Executes CODE if current cell is positive. This makes the esolang capable of running different branches of code according to different cell values.

Examples

Truth Machine

c[cscscsstttt.]cscccscttstt.

Interpreters

In Python, requires the mpmath library:

import sys
from mpmath import *
mp.dps=100 # 100 digits should be enough
def tbf(code):
    s=[]
    matches={}
    tape=[mpf(0)]*2000000
    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=1000000
    while cp<len(code):
        if code[cp]=='s':
            tape[p]=sin(tape[p])
        if code[cp]=='c':
            tape[p]=cos(tape[p])
        if code[cp]=='t':
            tape[p]=tan(tape[p])
        if code[cp]==',':
            c=sys.stdin.read(1)
            tape[p]=(ord(c) if c else 0)%256
        if code[cp]=='.':
            print(chr(int(round(tape[p],0))),end='')
        if code[cp]=='<':
            p-=1
        if code[cp]=='>':
            p+=1
        if code[cp]=='[':
            if tape[p]<=0:
                cp=matches[cp]
        if code[cp]==']':
            if tape[p]>0:
                cp=matches[cp]
        cp+=1
tbf(sys.stdin.read())

Computational class

Turing complete, for brainfuck is Turing-complete even if only changing 0s into 1s is allowed.