Skip to content

Instantly share code, notes, and snippets.

@whosaysni
Last active December 18, 2015 07:49
Show Gist options
  • Save whosaysni/5749644 to your computer and use it in GitHub Desktop.
Save whosaysni/5749644 to your computer and use it in GitHub Desktop.
とこちゃんはどこ
# 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