"""
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)
