Skip to content

Instantly share code, notes, and snippets.

@yaotti
Created December 17, 2009 06:27
Show Gist options
  • Save yaotti/258562 to your computer and use it in GitHub Desktop.
Save yaotti/258562 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding: utf-8
# http://ameblo.jp/programming/entry-10001721422.html
class Cards:
@classmethod
def deal(cls, num, string):
cds = [""]*num
for i in xrange(len(string) / num):
for j in xrange(num):
cds[j] += string[i*num+j]
return cds
def test(num, string, result):
assert Cards.deal(num, string) == result
if __name__ == '__main__':
test(3, "123123123", ["111","222","333"])
test(4, "123123123", ["12","23","31","12"])
test(10, "123123123", [""]*10)
test(4, "", [""]*4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment