Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2015
182
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def r_series(n):
  2.     'Hofstadter’s FIGURE-FIGURE Sequences'
  3.     def r(n):
  4.         if n<=1:return 1
  5.         else:return r(n-1)+s(n-1, r_list)
  6.     def s(n, r_list):
  7.         if n<=1: return 2
  8.         else:
  9.             check = False
  10.             i=1
  11.             while not check:
  12.                 if s(n-1,r_list)+i not in r_list: break
  13.                 i+=1
  14.             return s(n-1,r_list)+i
  15.     r_list=[]
  16.     for i in xrange(1,n):r_list.append(r(i))
  17.     return r(n)
  18.  
  19. def s_series(n):
  20.     return r_series(n+1) -r_series(n)
  21.  
  22.  
  23. print [r_series(x) for x in xrange(1,10)]
  24. print [s_series(x) for x in xrange(1,10)]
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement