Last active
December 18, 2015 07:49
-
-
Save whosaysni/5749644 to your computer and use it in GitHub Desktop.
とこちゃんはどこ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
"""とこちゃんはどこ | |
""" | |
from random import choice, randrange | |
import random, sys | |
s = ["と", "こ", "ち", "ゃ", "ん"] | |
def tokochan(width, height): | |
dx, dy = choice([(0, 1), (0, -1), (1, 0), (1, 1), | |
(1, -1), (-1, 0), (-1, 1), (-1, -1)]) | |
x = randrange(len(s) if dx==-1 else 0, width-(len(s) if dx==1 else 0)) | |
y = randrange(len(s) if dy==-1 else 0, height-(len(s) if dy==1 else 0)) | |
sparse = [(x+i*dx, y+i*dy) for i in range(len(s))] | |
for r in xrange(height): | |
for c in xrange(width): | |
sys.stdout.write( | |
s[sparse.index((c, r))] if (c, r) in sparse else choice(s)) | |
sys.stdout.write('\n') | |
tokochan(10, 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment