/polyomino-1

A lib to solve tasks related to polyminoes

Primary LanguagePython

Polyomino Lib

polyomino.py forked from this repo

This lib uses Knuth's Algorithm X to arrange polyominoes on given figure. Also it have parser.py module to load polyominoes from .pol files and pretty-print them to console or write to svg files.

Installation

Just clone this repo:

$ git clone

$ cd polyomino

$ python main.py

Examples

Find some arrangement of dominoes on 6x6 board:

import parser
import solver

figure = parser.load('figure.pol')
# File contains
# XXXXXX
# XXXXXX
# XXXXXX
# XXXXXX
# XXXXXX
# XXXXXX

part = parser.load('part.pol')
# File contains
# XX

for idx, s in enumerate(solver.split_into_parts(figure, part)):
    parser.save_solution_to_svg(s, str(idx)+'th_sol.svg')
    parser.pretty_print_solution(s)
    break # Because there are 6727 different arrangements

Find all arrangements of equal tetraminoes on 4x4 board:

import parser
import solver

figure = parser.load('figure.pol')
# File contains
# XXXX
# XXXX
# XXXX
# XXXX

# auto_congruent_polyomino_split will do all work for you
for idx, s in enumerate(solver.auto_congruent_polyomino_split(figure, 4)):
    parser.save_solution_to_svg(s, str(idx)+'th_sol.svg')
    parser.pretty_print_solution(s)
    print()

You'll have 15 different solutions:

Picture