FANDOM


I thought it would be interesting to put the BEAF system into python 3 for the sake of completeness. So far, only linear arrays are supported. Further dimensions might come later. Optimization/obfuscation suggestions are welcome! For inquiries concerning BEAF arrays with two or fewer entries, consult your local calculator.
def beaf(A):

if len(A)<3: raise TypeError('Only BEAF arrays of length 3 or greater are supported.')
if A[1]==1: return A[0]
trivial,pilot= True,2
while pilot<len(A) and A[pilot]==1: pilot+=1
if pilot!=len(A): trivial= False
if trivial: return A[0]**A[1]
passengers= []
for i in range(pilot-1): passengers+=[A[0]]
return beaf(passengers+[beaf([A[0]]+[A[1]-1]+A[2:])]+[A[pilot]-1]+A[pilot+1:])

a= [3,2,3]
print('{} = {}'.format('{'+str(a)[1:-1]+'}',beaf(a)))

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.