Anonymous user
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
((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
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(
▲def tile(board, i, seq=tuple()):
▲ if not i:
yield img(seq)
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)▼
tnext = [] # not using list comprehension ...
tnext.append(tuple(n for n in t if not n&b))
if not tnext[-1]: break # because early break is faster
else:
for
print(x)</lang>
{{out}}
<pre> ┌─┬───┬───────┐
┌─┘ └─┐ └─┬─┐ ┌─┤
├─┐ ┌─┼─┐ │ └─┘ │
│ ├─┤ └─┴─┼─┬───┤
│ │ └───┐ ├─┴─┐ │
│ │ ┌─┬─┴─┘ ┌─┤ │
│ ├─┤ ├───┬─┘ │ │
├─┴─┘ │ └─┐ └─┤
└─────┴─────┴───┘
┌─┬───┐ ┌─┬───┐
▲ _ _ _ _ _ _
┌─┘ └─┐ └─┤ └─┐ │
├─┐ ┌─┼─┐ │ ┌─┘ │
│ ├─┤ └─┴─┤ ├───┤
│ │ └───┐ ├─┴─┐ │
│ │ ┌─┬─┴─┘ ┌─┤ │
│ ├─┤ ├───┬─┘ │ │
├─┴─┘ │ └─┐ └─┤
└─────┴─────┴───┘</pre>
=={{header|Raku}}==
|