예제 #1
0
 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")
예제 #2
0
 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 ")
예제 #3
0
 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")
예제 #4
0
#!/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)
예제 #5
0
from second_code import SimpleBars

bs = SimpleBars(" " * 24)
bs[8] = "T"
for i in range(30):
    print(bs.next())
예제 #6
0
# -*- 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
예제 #7
0
#!/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)
예제 #8
0
 def test_len(self):
     self.assertEquals(len(SimpleBars("iTiTi")), 5)
     self.assertEquals(len(SimpleBars(" " * 80)), 80)
예제 #9
0
 def test_str(self):
     self.assertEquals(str(SimpleBars("     ")), "     ")
     self.assertEquals(str(SimpleBars("iTiTi")), "iTiTi")
예제 #10
0
    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)