Jump to content

Pentomino tiling: Difference between revisions

→‎{{header|Python}}: pre-generate shifted minos
(→‎{{header|Python}}: pre-generate shifted minos)
Line 1,473:
=={{header|Python}}==
<lang python>from itertools import product
 
minos = (((197123, 7, 6), (1797, 6, 7), (1287, 6, 7), (196867, 7, 6)), ((263937, 6, 6), (197126, 6, 6), (393731, 6, 6), (67332, 6, 6)),
((16843011, 7, 5), (2063, 5, 7), (3841, 5, 7), (271, 5, 7), (3848, 5, 7), (50463234, 7, 5), (50397441, 7, 5), (33686019, 7, 5)),
Line 1,485 ⟶ 1,486:
((132866, 6, 6),))
 
tiles = []
def show(seq):
for c, x, yrow in minos[i - 1]:
tiles.append([])
for n, x, y in row:
for shift in (b*8 + a for a, b in product(range(x), range(y))):
tiles[-1].append(n << shift)
 
 
def showimg(seq):
b = [[-1]*10 for _ in range(10)]
 
Line 1,496 ⟶ 1,505:
hori = ([' _'[b[i+1][j] != b[i][j]] for j in range(1, 10)] for i in range(9))
 
print(return '\n'.join([''.join(a + b for a, b in zip(v, h)) for v, h in zip(vert, hori)]))
 
 
def tile(board, i, seq=tuple()):
if not i:
showyield img(seq)
else: return
for c in [c for c in tiles[i - 1] if not board & c]:
yield from tile(board|ccc, i - 1, (ccc,) + seq)
 
for i in tile(0, len(minostiles)): print(i)</lang>
for c, x, y in minos[i - 1]:
for shift in (b*8 + a for a, b in product(range(x), range(y))):
if not ((cc := c<<shift) & board):
tile(board|cc, i - 1, (cc,) + seq)
 
tile(0, len(minos))</lang>
{{out}}
<pre> _ _ _ _ _ _ _
Line 1,532 ⟶ 1,538:
.
.</pre>
 
=={{header|Raku}}==
{{trans|Java}}
Cookies help us deliver our services. By using our services, you agree to our use of cookies.