BrainPi
Jump to navigation
Jump to search
BrainPi is an esolang invented by User:None1 on the Pi day of 2024 (2024/3/14). It is like Goldfuck except that it uses Pi instead of phi.

Examples
Hello World
3.1415926835897932384426433832695028841971893993721058206749445923073164062812089986280378253421190679821490865132803066450938446095501822317258594081284815174502041027029385216055596446229689549303819694288109756656334465284754482334867831653712019091456085669834603486704543266481133936071602491419737245878066063155851748875209209628092540917155643676925903600123305308488204965213881469512415116099330572703637595912530921871173819326717931551185080744823799927495973518857525248917279381830159491295336733824406566434860213549463952447371907023
Cat Program
3.1415926532897932384676433832795008841971698993751058259749445923079
Truth Machine
3.14159365358479323046264338367950288419416939937510182097494459730781640128620799862801482534711706768214808051328630664709384410955098223172595940812848113745028010270103852115555964462296895493538196402881097566597344611847564823372678316527170190914564855
Nope. interpreter
3.1415926335897939384626453832795628841972693993731058209749455923048164062462089983280348233421170879821483865132803066470538446093505822357253594581284819174502881027019285211065596446299489549303811644283109756659344461264756482137867832652712029091456985669233603486124543266082133930072602421412737545870069063155881743815206209628232540917553643670925903690113305605488201665213861469519815116092330572733657596919530928861173819326917931151185481744623799697495673018857527244912279388830119498298336736624406564430860212949463957247371901021798603437027703392171764931767529846748184666694071320005581271451635608247857713027577898091736371780214686409012279534301865495852710507962796892189235429199561151290219008640349181598436297747513099605187092113439999983129780499512
Output the first 7 digits of pi (3.1415926)
3.1415926635897931384626453832795928841978693993721058209049445923078264062662089981280348263421170079821481865132893066470038446094505822417253594581284811174552841037019385911055592446229489579303819694288109726659334411284756452337867861652712019491456486669234673486104643266482139936072692491412437245871066063155861748815249209628282540917143643678925503600119305305438204665313841468519415116004330572603657598919530951861173919326117938051185489744623797627495674518857522248912276381830113491298338733624406526430860413949466952247381907021398609437021
(Originally +++++++[>+++++++<-]>++.-----.+++.+++.---.++++.++++.-------.++++. in BF)
Interpreter in Python
Requires the precreal package which implements float without precision loss. As the package is written in pure Python, running large programs (e.g.: Hello World program) may be a bit slow.
import sys,precreal
def bf(code):
s1=[]
s2=[]
matches={}
tape=[0]*1000000
for i,j in enumerate(code):
if j=='[':
s1.append(i)
if j==']':
m=s1.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]==',':
tape[p]=ord(sys.stdin.read(1))%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
def fuck2bf(code):
cleancode=''
for i in code:
if i in '!#':
cleancode+=i
cp=0
table=' ><+-,.[]'
b=''
while cp<len(cleancode):
idx=cleancode.index('#',cp)-cp
b+=table[idx]
cp+=idx+1
return b
def run(code):
bf(fuck2bf(code))
code=input()[2:]
pi_digits=str(precreal.pi(len(code)))[2:]
ef_code=''
for i,j in enumerate(code):
if pi_digits[i]!=j:
ef_code+='#'
else:
ef_code+='!'
run(ef_code)