"""
472 名前:デフォルトの名無しさん[sage] 投稿日:2014/07/10(木) 17:55:09.45 ID:G1rqgd7K
縦H * 横W ( 10≦(H, W)≦100 )のサイズの床に地雷を設置した
---**
--*--
-*---
--*--
*--*-
以下のように地雷に隣接する床の上に、隣合う地雷の数を調べて出力できるプログラムを作成せよ
地雷をランダムに配置せよ
002**
02*21
1*300
12*20
*12*1
"""
import random
def f(H,W,N=None):
if not N:
N = int(reduce(lambda a,b: a*(H*W)+b, (0.000235,0.0938,0.8937)))
board = [[0 for x in range(W)] for y in range(H)]
bombs = set()
while len(bombs) < N:
bombs.add((random.randrange(W), random.randrange(H)))
for x,y in bombs:
board[y][x] = "*"
for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]:
x2,y2 = x+dx,y+dy
if 0 <= x2 < W and 0 <= y2 < H and board[y2][x2] != "*":
board[y2][x2] += 1
for row in board:
print "".join(map(str, row)).replace("0", "-")
#f(5,5)
#f(9,9)
#f(16,16)
f(16,30)
IiIiCjQ3MiDlkI3liY3vvJrjg4fjg5Xjgqnjg6vjg4jjga7lkI3nhKHjgZfjgZXjgpNbc2FnZV0g5oqV56i/5pel77yaMjAxNC8wNy8xMCjmnKgpIDE3OjU1OjA5LjQ1IElEOkcxcnFnZDdLCue4pkggKiDmqKpXICggMTDiiaYoSCwgVyniiaYxMDAgKeOBruOCteOCpOOCuuOBruW6iuOBq+WcsOmbt+OCkuioree9ruOBl+OBnwotLS0qKgotLSotLQotKi0tLQotLSotLQoqLS0qLQrku6XkuIvjga7jgojjgYbjgavlnLDpm7fjgavpmqPmjqXjgZnjgovluorjga7kuIrjgavjgIHpmqPlkIjjgYblnLDpm7fjga7mlbDjgpLoqr/jgbnjgablh7rlipvjgafjgY3jgovjg5fjg63jgrDjg6njg6DjgpLkvZzmiJDjgZvjgogK5Zyw6Zu344KS44Op44Oz44OA44Og44Gr6YWN572u44Gb44KICjAwMioqCjAyKjIxCjEqMzAwCjEyKjIwCioxMioxCiIiIgoKaW1wb3J0IHJhbmRvbQpkZWYgZihILFcsTj1Ob25lKToKICAgIGlmIG5vdCBOOgogICAgICAgIE4gPSBpbnQocmVkdWNlKGxhbWJkYSBhLGI6IGEqKEgqVykrYiwgKDAuMDAwMjM1LDAuMDkzOCwwLjg5MzcpKSkKICAgIGJvYXJkID0gW1swIGZvciB4IGluIHJhbmdlKFcpXSBmb3IgeSBpbiByYW5nZShIKV0KICAgIGJvbWJzID0gc2V0KCkKICAgIHdoaWxlIGxlbihib21icykgPCBOOgogICAgICAgIGJvbWJzLmFkZCgocmFuZG9tLnJhbmRyYW5nZShXKSwgcmFuZG9tLnJhbmRyYW5nZShIKSkpCiAgICBmb3IgeCx5IGluIGJvbWJzOgogICAgICAgIGJvYXJkW3ldW3hdID0gIioiCiAgICAgICAgZm9yIGR4LGR5IGluIFsoMSwwKSwoLTEsMCksKDAsMSksKDAsLTEpXToKICAgICAgICAgICAgeDIseTIgPSB4K2R4LHkrZHkKICAgICAgICAgICAgaWYgMCA8PSB4MiA8IFcgYW5kIDAgPD0geTIgPCBIIGFuZCBib2FyZFt5Ml1beDJdICE9ICIqIjoKICAgICAgICAgICAgICAgIGJvYXJkW3kyXVt4Ml0gKz0gMQogICAgZm9yIHJvdyBpbiBib2FyZDoKICAgICAgICBwcmludCAiIi5qb2luKG1hcChzdHIsIHJvdykpLnJlcGxhY2UoIjAiLCAiLSIpCgojZig1LDUpCiNmKDksOSkKI2YoMTYsMTYpCmYoMTYsMzApCg==