def test_loop(self): bs = SimpleBars("Ti ") self.assertEquals(str(bs.next()), " Ti ") self.assertEquals(str(bs.next()), " Ti") self.assertEquals(str(bs.next()), "i T") self.assertEquals(str(bs.next()), "Ti ") bs = SimpleBars(" iT") self.assertEquals(str(bs.next()), " iT ") self.assertEquals(str(bs.next()), "iT ") self.assertEquals(str(bs.next()), "T i") self.assertEquals(str(bs.next()), " iT")
def test_simple_rule(self): self.assertEquals(str(SimpleBars(" ").next()), " ") self.assertEquals(str(SimpleBars(" i ").next()), " iTi ") self.assertEquals(str(SimpleBars(" i i ").next()), "iT Ti") self.assertEquals(str(SimpleBars(" T ").next()), " i ") self.assertEquals(str(SimpleBars(" TiT ").next()), " T ") self.assertEquals(str(SimpleBars(" iTi ").next()), "iTiTi") self.assertEquals(str(SimpleBars(" TTT ").next()), " iii ")
#!/usr/bin/env python # -*- mode: python; coding: utf-8-unix -*- # http://cp1.nintendo.co.jp/2012 from second_code import SimpleBars import re bs = SimpleBars(' '*78) pos = 0; acc = 1; accx = 1; output = "" commands = "1(///(1iTiTiTi|||[(1 ])1( [L|[L|[L|[(] |1//)/)1i||1)///)1i||||1(///)1i\ (/////)1iTiTi[L!])|])[L!])])l|])1/( [(1/ ]L!l|[(1 ])1( //(1 ]L[L!|" for c in commands: if c == "1": acc = 1 elif c == "/": acc = acc * 2 elif c == ")": pos += acc; pos %= len(bs) elif c == "(": pos -= acc; pos %= len(bs) elif c == "i" or c == "T" or c == " ": for i in range(acc): bs[pos] = c; pos += 1; pos %= len(bs) elif c == "]": s = str(bs)[pos:]+str(bs)[:pos+1]; m = re.search("^ *[iT]* ", s) acc = (m and m.end() - 1) or 0 elif c == "[": t = str(bs); s = t[pos-1]+t[pos:]+t[:pos]; m = re.search(" [iT]* *$", s) acc = (m and len(s) - m.start() - 1) or 0 elif c == "l": acc, accx = accx, acc elif c == "L": acc, accx = accx - acc, accx + acc elif c == "|": print(bs); bs.next() elif c == "!": output += chr((ord('0') + acc) % 128)
from second_code import SimpleBars bs = SimpleBars(" " * 24) bs[8] = "T" for i in range(30): print(bs.next())
# -*- coding: utf-8 -*- from second_code import SimpleBars if __name__ == '__main__': aa = list("abc") print aa bs = SimpleBars("abc") print bs bs_next = bs.next() print bs_next
#!/usr/bin/env python from second_code import SimpleBars import re bs = SimpleBars(' '*78) pos = 0; acc = 1; accx = 1; output = "" commands = "1(///(1iTiTiTi|||[(1 ])1( [L|[L|[L|[(] |1//)/)1i||1)///)1i||||1(///)1i\ (/////)1iTiTi[L!])|])[L!])])l|])1/( [(1/ ]L!l|[(1 ])1( //(1 ]L[L!|" for c in commands: if c == "1": acc = 1 elif c == "/": acc = acc * 2 elif c == ")": pos += acc; pos %= len(bs) elif c == "(": pos -= acc; pos %= len(bs) elif c == "i" or c == "T" or c == " ": for i in range(acc): bs[pos] = c; pos += 1; pos %= len(bs) elif c == "]": s = str(bs)[pos:]+str(bs)[:pos+1]; m = re.search("^ *[iT]* ", s) acc = (m and m.end() - 1) or 0 elif c == "[": t = str(bs); s = t[pos-1]+t[pos:]+t[:pos]; m = re.search(" [iT]* *$", s) acc = (m and len(s) - m.start() - 1) or 0 elif c == "l": acc, accx = accx, acc elif c == "L": acc, accx = accx - acc, accx + acc elif c == "|": print(bs); bs.next() elif c == "!": output += chr((ord('0') + acc) % 128) print("answer: " + output)
def test_len(self): self.assertEquals(len(SimpleBars("iTiTi")), 5) self.assertEquals(len(SimpleBars(" " * 80)), 80)
def test_str(self): self.assertEquals(str(SimpleBars(" ")), " ") self.assertEquals(str(SimpleBars("iTiTi")), "iTiTi")
def test_simple_rule(self): self.assertEquals(str(SimpleBars(" ").next()), " ") self.assertEquals(str(SimpleBars(" i ").next()), " iTi ") self.assertEquals(str(SimpleBars(" i i ").next()), "iT Ti") self.assertEquals(str(SimpleBars(" T ").next()), " i ") self.assertEquals(str(SimpleBars(" TiT ").next()), " T ") self.assertEquals(str(SimpleBars(" iTi ").next()), "iTiTi") self.assertEquals(str(SimpleBars(" TTT ").next()), " iii ") def test_loop(self): bs = SimpleBars("Ti ") self.assertEquals(str(bs.next()), " Ti ") self.assertEquals(str(bs.next()), " Ti") self.assertEquals(str(bs.next()), "i T") self.assertEquals(str(bs.next()), "Ti ") bs = SimpleBars(" iT") self.assertEquals(str(bs.next()), " iT ") self.assertEquals(str(bs.next()), "iT ") self.assertEquals(str(bs.next()), "T i") self.assertEquals(str(bs.next()), " iT") def tearDown(self): pass if __name__ == "__main__": print(str(SimpleBars(" Ti ").next())) suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(testSimpleBars)) unittest.TextTestRunner(verbosity=2).run(suite)