f we define the following simple grammar:
- variables : A B
- constants : none
- start : A
- rules : (A → B), (B → AB)
then this L-system produces the following sequence of strings:
- n = 0 : A
- n = 1 : B
- n = 2 : AB
- n = 3 : BAB
- n = 4 : ABBAB
- n = 5 : BABABBAB
- n = 6 : ABBABBABABBAB
- n = 7 : BABABBABABBABBABABBAB
def fib(n): if n == 0: return 'A' if n == 1: return 'B' else: return fib(n-2)+fib(n-1) n = int(raw_input("enter number of generation (zero-based):\n")) for i in range(n): print 'n = %d: %s' % (i, fib(i))
|
阅读(563) | 评论(0) | 转发(0) |