Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def eca(cells, rule):
- lencells = len(cells)
- c = "0" + cells + "0" # Zero pad the ends
- rulebits = '{0:08b}'.format(rule)
- neighbours2next = {'{0:03b}'.format(n):rulebits[::-1][n] for n in range(8)}
- yield c[1:-1]
- while True:
- c = ''.join(['0',
- ''.join(neighbours2next[c[i-1:i+2]]
- for i in range(1,lencells+1)),
- '0'])
- yield c[1:-1]
- if __name__ == '__main__':
- print("Генератор элементарных клеточных автоматов v0.3")
- #print("Привет!")
- a=-1;
- outputType=2
- #Проверка на корректность ввода 2
- while True:
- print("Введите начальные условия в виде 0 и 1.")
- a = str(input())
- correct = 1
- for i in range(0,len(a)):
- if a[i] != '1' and a[i]!='0':
- correct=0
- if correct==0 or len(a) ==0:
- print("Ошибка, повторите ввод.")
- else:
- break
- # print("Введите номер правила в целочисленном виде")
- rule = 60
- n=100
- i1 = '0'
- i2 = '1'
- lines, start, rules = n, a, rule
- zipped = [range(lines)] + [eca(start, rule)]
- print('\n Правило: %r' % (rules,))
- for data in zip(*zipped):
- i = data[0]
- cells = data[1:]
- print('%s' % (' '.join(cells).replace('0',i1).replace('1', i2)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement