SHARE
TWEET

Formula Checking Code

SOLinus Aug 24th, 2016 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #see http://codegolf.stackexchange.com/a/90883/46756
  2.  
  3. #define a working list to fill with representations which evaluate
  4. #to given values, and parameters for filling that list.
  5. m=11111      #bound for list
  6. R=range(0,m) #list for representations
  7. U=range(0,m) #code to see which formula was used
  8. R[1]="()"    #intiallize list
  9. R[2]="()()"
  10. l=2          #current least new represtation
  11.  
  12. #define a method to add a representation for a value to the list
  13. def a(v,r,u):
  14.  if v>0 and v<m:
  15.   if isinstance(R[v],int) or len(r)<len(R[v]):
  16.    R[v]=r
  17.    U[v]=-u
  18.    if v<R[0]:
  19.     R[0]=v
  20.  
  21. #define a sumation function
  22. def s(v,k):
  23.  S=0
  24.  while v>0:
  25.   S+=v
  26.   v-=k
  27.  return S
  28.  
  29. #shorthand for recurring brainflak structures
  30. p=lambda r:"("+r+")"         #store
  31. w=lambda r:"{({}["+r+"])}{}" #sum with increment
  32. def q(r,v):                  #multiply by v
  33.  for i in range(1,v):
  34.   r="("+r+")"
  35.  for i in range(1,v):
  36.   r+="{}"
  37.  return r
  38. def e(r,v,k):                #multiply by expontent v^k
  39.  for i in range(0,k):
  40.   r=q(r,v)
  41.  return r
  42.  
  43. #fill the array with new representations formed from existing
  44. #representations, if shorter.
  45. while l<m:
  46.  R[0]=l+1
  47.  #multiplications
  48.  a(l*2,q(R[l],2),1)
  49.  a(l*3,q(R[l],3),2)
  50.  a(l*5,q(R[l],5),3)
  51.  a(l*7,q(R[l],7),4)
  52.  a(l*11,q(R[l],11),5) #not found
  53.  a(l*13,q(R[l],13),6) #not found
  54.  for i in range(1,l):
  55.   #addition
  56.   a(l+i,R[l]+R[i],7)
  57.   #subtraction
  58.   a(l-i,R[l]+"["+R[i]+"]",8)
  59.   if 2*i<=l and l%i==0:#2*i<=l should save some time, is not golfed
  60.    t=s(l-i,i)
  61.    #sumations
  62.    a(s(l,i),p(R[l])+w(R[i]),9)
  63.    #multiples of sums, plus
  64.    a(l+2*t,p(R[l])+q(w(R[i]),2),11)
  65.    a(l+4*t,p(R[l])+e(w(R[i]),2,2),12)
  66.    a(l+8*t,p(R[l])+e(w(R[i]),2,3),13)
  67.    a(l+16*t,p(R[l])+e(w(R[i]),2,4),14)
  68.    a(l+32*t,p(R[l])+e(w(R[i]),2,5),15)
  69.    a(l+64*t,p(R[l])+e(w(R[i]),2,6),16)
  70.    a(l+128*t,p(R[l])+e(w(R[i]),2,7),17)
  71.    a(l+256*t,p(R[l])+e(w(R[i]),2,8),18) #not found
  72.    a(l+512*t,p(R[l])+e(w(R[i]),2,9),19) #not found
  73.    a(l+1024*t,p(R[l])+e(w(R[i]),2,10),20) #not found
  74.    a(l+2048*t,p(R[l])+e(w(R[i]),2,11),21) #not found
  75.    a(l+4096*t,p(R[l])+e(w(R[i]),2,12),22) #not found
  76.    
  77.    a(l+3*t,p(R[l])+q(w(R[i]),3),23)
  78.    a(l+9*t,p(R[l])+e(w(R[i]),3,2),24)
  79.    a(l+27*t,p(R[l])+e(w(R[i]),3,3),25)
  80.    a(l+81*t,p(R[l])+e(w(R[i]),3,4),26) #not found
  81.    a(l+243*t,p(R[l])+e(w(R[i]),3,5),27) #not found
  82.    a(l+729*t,p(R[l])+e(w(R[i]),3,6),28) #not found
  83.    
  84.    a(l+5*t,p(R[l])+q(w(R[i]),5),29)
  85.    a(l+25*t,p(R[l])+e(w(R[i]),5,2),30) #not found
  86.    a(l+125*t,p(R[l])+e(w(R[i]),5,3),31) #not found
  87.    
  88.    a(l+7*t,p(R[l])+q(w(R[i]),7),32) #not found
  89.    a(l+49*t,p(R[l])+e(w(R[i]),7,2),33) #not found
  90.    
  91.    a(l+11*t,p(R[l])+q(w(R[i]),11),34) #not found
  92.  
  93.    a(l+6*t,p(R[l])+q(q(w(R[i]),3),2),35)
  94.    a(l+10*t,p(R[l])+q(q(w(R[i]),5),2),36)
  95.    a(l+14*t,p(R[l])+q(q(w(R[i]),7),2),37) #not found
  96.    a(l+22*t,p(R[l])+q(q(w(R[i]),11),2),38) #not found
  97.    a(l+15*t,p(R[l])+q(q(w(R[i]),5),3),39)
  98.    a(l+21*t,p(R[l])+q(q(w(R[i]),7),3),40) #not found
  99.    a(l+33*t,p(R[l])+q(q(w(R[i]),11),3),41) #not found
  100.    a(l+35*t,p(R[l])+q(q(w(R[i]),7),5),42) #not found
  101.    a(l+55*t,p(R[l])+q(q(w(R[i]),11),5),43) #not found
  102.    a(l+77*t,p(R[l])+q(q(w(R[i]),11),7),44) #not found
  103.    
  104.    a(l+12*t,p(R[l])+q(q(q(w(R[i]),3),2),2),45)
  105.    a(l+18*t,p(R[l])+q(q(q(w(R[i]),3),3),2),46)
  106.    a(l+20*t,p(R[l])+q(q(q(w(R[i]),5),2),2),47)
  107.    a(l+30*t,p(R[l])+q(q(q(w(R[i]),5),3),2),48) #not found
  108.    a(l+50*t,p(R[l])+q(q(q(w(R[i]),5),5),2),49) #not found
  109.    a(l+45*t,p(R[l])+q(q(q(w(R[i]),5),3),3),50) #not found
  110.    a(l+75*t,p(R[l])+q(q(q(w(R[i]),5),5),3),51) #not found
  111.    a(l+28*t,p(R[l])+q(q(q(w(R[i]),7),2),2),52) #not found
  112.    a(l+42*t,p(R[l])+q(q(q(w(R[i]),7),3),2),53) #not found
  113.    a(l+70*t,p(R[l])+q(q(q(w(R[i]),7),5),2),54) #not found
  114.    a(l+98*t,p(R[l])+q(q(q(w(R[i]),7),7),2),55) #not found
  115.    a(l+63*t,p(R[l])+q(q(q(w(R[i]),7),3),3),56) #not found
  116.    a(l+105*t,p(R[l])+q(q(q(w(R[i]),7),5),3),57) #not found
  117.    a(l+147*t,p(R[l])+q(q(q(w(R[i]),7),7),3),58) #not found
  118.    a(l+175*t,p(R[l])+q(q(q(w(R[i]),7),5),5),59) #not found
  119.    a(l+245*t,p(R[l])+q(q(q(w(R[i]),7),7),5),60) #not found
  120.    
  121.    a(l+44*t,p(R[l])+q(q(q(w(R[i]),11),2),2),61) #not found
  122.    a(l+66*t,p(R[l])+q(q(q(w(R[i]),11),3),2),62) #not found
  123.    a(l+99*t,p(R[l])+q(q(q(w(R[i]),11),3),3),63) #not found
  124.    
  125.    a(l+24*t,p(R[l])+q(q(q(q(w(R[i]),3),2),2),2),64)
  126.    a(l+36*t,p(R[l])+q(q(q(q(w(R[i]),3),3),2),2),65)
  127.    a(l+54*t,p(R[l])+q(q(q(q(w(R[i]),3),3),3),2),66) #not found
  128.    a(l+40*t,p(R[l])+q(q(q(q(w(R[i]),5),2),2),2),67)
  129.    a(l+60*t,p(R[l])+q(q(q(q(w(R[i]),5),3),2),2),68) #not found
  130.    a(l+90*t,p(R[l])+q(q(q(q(w(R[i]),5),3),3),2),69) #not found
  131.    a(l+135*t,p(R[l])+q(q(q(q(w(R[i]),5),3),3),3),70) #not found
  132.    a(l+56*t,p(R[l])+q(q(q(q(w(R[i]),7),2),2),2),71) #not found
  133.  
  134.  l=R[0]
  135.  
  136. #return final representation of a value
  137. f=lambda v:p(R[v])
  138.  
  139.  
  140. #THIS ENDS THE GOLFED REPRESENTATION PART OF THE PROGRAM
  141. def isPrime(v):
  142.  i=2
  143.  while i*i<=v:
  144.   if v%i==0:
  145.    return False
  146.   i+=1
  147.  return True
  148.  
  149. for i in range(1,m):
  150.  #if isPrime(i):, while testing which formula are used, since
  151.  #only the last formula used is shown we need to see all numbers
  152.   print str(U[i])+" "+f(i)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top