Pentomino tiling: Difference between revisions
Content added Content deleted
(→{{header|Python}}: pre-generate shifted minos) |
(→{{header|Python}}: speed improvement; change to unicode box drawing chars) |
||
Line 1,474: | Line 1,474: | ||
<lang python>from itertools import product |
<lang python>from itertools import product |
||
minos = (((197123, 7, 6), (1797, 6, 7), (1287, 6, 7), (196867, 7 |
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)), |
((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)), |
((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: | Line 1,486: | ||
((4311810305, 8, 4), (31, 4, 8)), |
((4311810305, 8, 4), (31, 4, 8)), |
||
((132866, 6, 6),)) |
((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 = [] |
tiles = [] |
||
for row in minos: |
for row in reversed(minos): |
||
tiles.append([]) |
tiles.append([]) |
||
for n, x, y in row: |
for n, x, y in row: |
||
for shift in (b*8 + a for a, b in product(range(x), range(y))): |
for shift in (b*8 + a for a, b in product(range(x), range(y))): |
||
tiles[-1].append(n << shift) |
tiles[-1].append(n << shift) |
||
def img(seq): |
def img(seq): |
||
Line 1,502: | Line 1,507: | ||
b[j + 1][k + 1] = i |
b[j + 1][k + 1] = i |
||
idices = [[0]*9 for _ in range(9)] |
|||
for i, j in product(range(9), 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( |
return '\n'.join(''.join(patterns[i] for i in row) for row in idices) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
yield img(seq) |
yield img(seq) |
||
return |
|||
⚫ | |||
for c in tiles[0]: |
|||
⚫ | |||
⚫ | |||
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 |
for x in tile(): |
||
print(x)</lang> |
|||
{{out}} |
{{out}} |
||
<pre> ┌─┬───┬───────┐ |
|||
<pre> _ _ _ _ _ _ _ |
|||
┌─┘ └─┐ └─┬─┐ ┌─┤ |
|||
_| |_ |_ _ _| |
|||
├─┐ ┌─┼─┐ │ └─┘ │ |
|||
|_ _|_ | |_| | |
|||
│ ├─┤ └─┴─┼─┬───┤ |
|||
| |_| |_|_|_ _ _| |
|||
│ │ └───┐ ├─┴─┐ │ |
|||
| | |_ _ |_|_ | |
|||
│ │ ┌─┬─┴─┘ ┌─┤ │ |
|||
| | _ _|_| _| | |
|||
│ ├─┤ ├───┬─┘ │ │ |
|||
| |_| |_ _ _| | | |
|||
├─┴─┘ │ └─┐ └─┤ |
|||
|_|_| | |_ |_| |
|||
└─────┴─────┴───┘ |
|||
|_ _ _|_ _ _|_ _| |
|||
┌─┬───┐ ┌─┬───┐ |
|||
⚫ | |||
┌─┘ └─┐ └─┤ └─┐ │ |
|||
_| |_ |_| |_ | |
|||
├─┐ ┌─┼─┐ │ ┌─┘ │ |
|||
|_ _|_ | _| | |
|||
│ ├─┤ └─┴─┤ ├───┤ |
|||
| |_| |_|_| |_ _| |
|||
│ │ └───┐ ├─┴─┐ │ |
|||
| | |_ _ |_|_ | |
|||
│ │ ┌─┬─┴─┘ ┌─┤ │ |
|||
| | _ _|_| _| | |
|||
│ ├─┤ ├───┬─┘ │ │ |
|||
| |_| |_ _ _| | | |
|||
├─┴─┘ │ └─┐ └─┤ |
|||
|_|_| | |_ |_| |
|||
└─────┴─────┴───┘</pre> |
|||
|_ _ _|_ _ _|_ _| |
|||
. |
|||
. |
|||
.</pre> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |