dragonline.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # draw dragon line base on requested times
  2. '''
  3. altorithm:
  4. 1st move: [F]oward
  5. 2nd move: [L]eft turn
  6. 3rd move: [F]oward
  7. the n'nd wrap, will create 2^(n-1)'s turnning point, and they follow the order(LRLRLRLR),
  8. in the location(1,3,5,..-3,-1), while turning direction at location x would be the opposite of location -x.
  9. total turning point would be:
  10. 1 + 2^(2-1)+2^(3-1)+...+2^(n-1)
  11. it's n'nd wrap:
  12. location i's turning should be:
  13. l_new[i] = 'L' if i%2 == 0 else 'R'
  14. l_n[i] = l_new[i/2] if i%2 == 0 else l_(n-1)[int(i/2)]
  15. '''
  16. class DragonLine:
  17. def __init__(self):
  18. self.__turnflow = []
  19. def turn_flow(self,wrap):
  20. flow_origin = self.turn_flow(wrap-1) if wrap>2 else ['L']
  21. flow_new = ['L' if i%2 ==0 else 'R' for i in range(2**(wrap-1))]
  22. self.__turnflow = [i for i in range(2**wrap-1)]
  23. _range = 2**wrap-1
  24. self.__turnflow = [flow_new[int(i/2)] if i%2 == 0 else flow_origin[int(i/2)] for i in range(_range)]
  25. return self.__turnflow
  26. dragonline = DragonLine()
  27. print (dragonline.turn_flow(5))