Sha256: 66d46b21da6863cf1486c7546e2d3dc4a81c9a7d09ee6f5e797c0e5834868226

Contents?: true

Size: 1.27 KB

Versions: 155

Compression:

Stored size: 1.27 KB

Contents

def board(inp):
    verify_board(inp)
    rowlen = len(inp[0])
    collen = len(inp)
    b = [list(r) for r in inp]
    for i1 in range(collen):
        for i2 in range(rowlen):
            if b[i1][i2] != ' ':
                continue
            cnt = inp[i1 - 1][i2 - 1:i2 + 2].count('*') + \
                inp[i1][i2 - 1:i2 + 2].count('*') + \
                inp[i1 + 1][i2 - 1:i2 + 2].count('*')
            if cnt == 0:
                continue
            b[i1][i2] = str(cnt)
    return ["".join(r) for r in b]


def verify_board(inp):
    # Null board or a null row
    if not inp or not all(r for r in inp):
        raise ValueError("Invalid board")
    # Rows with different lengths
    rowlen = len(inp[0])
    collen = len(inp)
    if not all(len(r) == rowlen for r in inp):
        raise ValueError("Invalid board")
    # Unknown character in board
    cset = set()
    for r in inp:
        cset.update(r)
    if cset - set('+- *|'):
        raise ValueError("Invalid board")
    # Borders not as expected
    if any(inp[i1] != '+' + '-' * (rowlen - 2) + '+'
           for i1 in [0, -1]) or any(inp[i1][i2] != '|'
                                     for i1 in range(1, collen - 1)
                                     for i2 in [0, -1]):
        raise ValueError("Invalid board")

Version data entries

155 entries across 155 versions & 1 rubygems

Version Path
trackler-2.1.0.26 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.25 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.24 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.23 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.22 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.21 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.20 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.19 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.18 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.17 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.16 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.15 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.14 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.13 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.12 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.11 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.10 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.9 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.8 tracks/python/exercises/minesweeper/example.py
trackler-2.1.0.7 tracks/python/exercises/minesweeper/example.py