Jump to content

Pentomino tiling: Difference between revisions

→‎{{header|Python}}: speed improvement; change to unicode box drawing chars
(→‎{{header|Python}}: pre-generate shifted minos)
(→‎{{header|Python}}: speed improvement; change to unicode box drawing chars)
Line 1,474:
<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)),
((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)),
((131843, 7, 6), (1798, 6, 7), (775, 6, 7), (1795, 6, 7), (1543, 6, 7), (197377, 7, 6), (197378, 7, 6), (66307, 7, 6)),
Line 1,485 ⟶ 1,486:
((4311810305, 8, 4), (31, 4, 8)),
((132866, 6, 6),))
 
# for drawing in terminal; correct aspect ratio depends on your terminal font
boxchar_double_width = ' ██┘█─└┴█┐│┤┌┬├┼'
boxchar_single_width = (' ', '██', '██', '┘ ', '██', '──', '└─', '┴─', '██', '┐ ', '│ ', '┤ ', '┌─', '┬─', '├─', '┼─')
patterns = boxchar_single_width
 
tiles = []
for row in reversed(minos):
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 img(seq):
Line 1,502 ⟶ 1,507:
b[j + 1][k + 1] = i
 
vertidices = ([' |'[row[i] != row[i+1]0]*9 for i_ in range(9)] for row in b)
horifor = ([' _'[b[i+1][j] != b[i][j]] for, j in product(range(19), 10)] for i in range(9)):
n = (b[i][j], b[i][j+1], b[i+1][j+1], b[i+1][j])
idices[i][j] = sum((n[i] != n[i - 1])<<i for i in range(4))
 
return '\n'.join([''.join(a + bpatterns[i] for a, bi in zip(v, h)row) for v, hrow in zip(vert, hori)]idices)
 
def tile(board, i=0, seq=tuple(), tiles=tiles):
 
if not itiles:
def tile(board, i, seq=tuple()):
if not i:
yield img(seq)
else: return
 
for c in [c for c in tiles[i - 1] if not board & c]:
for c in tiles[0]:
yield from tile(board|c, i - 1, (c,) + seq)
_ _ _ _b _= _board | c
 
tnext = [] # not using list comprehension ...
for c in [c for ct in tiles[i - 1] if not board & c:]:
tnext.append(tuple(n for n in t if not n&b))
if not tnext[-1]: break # because early break is faster
else:
yield from tile(board|cb, iseq - 1,+ (c,), + seqtnext)
 
for ix in tile(0, len(tiles)): print(i)</lang>
print(x)</lang>
{{out}}
<pre> ┌─┬───┬───────┐
<pre> _ _ _ _ _ _ _
┌─┘ └─┐ └─┬─┐ ┌─┤
_| |_ |_ _ _|
├─┐ ┌─┼─┐ │ └─┘ │
|_ _|_ | |_| |
│ ├─┤ └─┴─┼─┬───┤
| |_| |_|_|_ _ _|
│ │ └───┐ ├─┴─┐ │
| | |_ _ |_|_ |
│ │ ┌─┬─┴─┘ ┌─┤ │
| | _ _|_| _| |
│ ├─┤ ├───┬─┘ │ │
| |_| |_ _ _| | |
├─┴─┘ │ └─┐ └─┤
|_|_| | |_ |_|
└─────┴─────┴───┘
|_ _ _|_ _ _|_ _|
┌─┬───┐ ┌─┬───┐
_ _ _ _ _ _
┌─┘ └─┐ └─┤ └─┐ │
_| |_ |_| |_ |
├─┐ ┌─┼─┐ │ ┌─┘ │
|_ _|_ | _| |
│ ├─┤ └─┴─┤ ├───┤
| |_| |_|_| |_ _|
│ │ └───┐ ├─┴─┐ │
| | |_ _ |_|_ |
│ │ ┌─┬─┴─┘ ┌─┤ │
| | _ _|_| _| |
│ ├─┤ ├───┬─┘ │ │
| |_| |_ _ _| | |
├─┴─┘ │ └─┐ └─┤
|_|_| | |_ |_|
└─────┴─────┴───┘</pre>
|_ _ _|_ _ _|_ _|
.
.
.</pre>
 
=={{header|Raku}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.