Created
January 13, 2016 10:49
-
-
Save avamsi/782d58f50aff4cf01acf 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
import itertools | |
import sys | |
inp = open(sys.argv[1]) | |
for field_count in itertools.count(1): | |
a, b = map(int, inp.readline().split()) | |
if a == 0: | |
break | |
field = [inp.readline().strip() for _ in xrange(a)] | |
out = [[0]*b for _ in xrange(a)] | |
for ai, bi in itertools.product(xrange(a), xrange(b)): | |
if field[ai][bi] == '*': | |
out[ai][bi] = '*' | |
for i in xrange(ai - 1, ai + 2): | |
for j in xrange(bi - 1, bi + 2): | |
if 0 <= i < a and 0 <= j < b and out[i][j] != '*': | |
out[i][j] += 1 | |
print 'Field %s' % field_count | |
print '\n'.join(''.join(map(str, i)) for i in out) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment