''' (c) MIT License by K. Urner More playing around with NKS for a Gnu Math class using Python NKS = new kind of science (Wolfram) i.e. cellular automata (CA) '''
def make_rule(n): """takes 0-255 and returns rule dict""" the_rule = {} values = "{:08b}".format(n) for x in range(8): key = "{:03b}".format(x) the_rule[key] = values[x] return the_rule def transcribe(s, r): """takes a row s and returns a row based on rule r""" n = 0 max = len(s) out = '' while n < max-2: triple = s[n:n+3] out += r[triple] n += 1 return out def generations(s, r, n=1): """applies rule r to transcribed output, starting with s, n times""" for _ in range(n): row = transcribe(s, r) s = row yield row rule130 = make_rule(130) top = '000000000000010000000000000' the_gen = generations(top, rule130, 10) dots=0 print(top) while True: dots += 1 try: print("."*dots, next(the_gen), sep="") except: break
_______________________________________________ Edu-sig mailing list Edu-sig@python.org https://mail.python.org/mailman/listinfo/edu-sig