Free polyominoes enumeration: Difference between revisions
Content added Content deleted
(Added Ruby) |
(→{{header|Ruby}}: reduction of the unnecessary argument) |
||
Line 671: | Line 671: | ||
end |
end |
||
def canonical(poly |
def canonical(poly) |
||
rotations_and_reflections(poly).map{|pl| translate2origin(pl)} |
|||
polys.each{|pl| pattern << pl} |
|||
polyomino << polys.min |
|||
end |
end |
||
Line 685: | Line 683: | ||
def new_points(poly) |
def new_points(poly) |
||
points = [] |
points = [] |
||
poly.each{|x,y| contiguous(x,y).each{| |
poly.each{|x,y| contiguous(x,y).each{|point| points << point}} |
||
(points - poly).uniq |
(points - poly).uniq |
||
end |
end |
||
def new_polys(polys) |
def new_polys(polys) |
||
polyomino = Set.new |
|||
pattern = Set.new |
pattern = Set.new |
||
polys. |
polys.each_with_object([]) do |poly, polyomino| |
||
new_points(poly).each do |point| |
new_points(poly).each do |point| |
||
pl = translate2origin(poly + [point]) |
next if pattern.include?(pl = translate2origin(poly + [point])) |
||
canonical(pl |
polyomino << canonical(pl).each{|p| pattern << p}.min |
||
end |
end |
||
end |
end |
||
polyomino.sort |
|||
end |
end |
||
Line 722: | Line 718: | ||
n = ARGV[0] ? ARGV[0].to_i : 5 |
n = ARGV[0] ? ARGV[0].to_i : 5 |
||
puts "\nAll free polyominoes of rank %d:" % n |
puts "\nAll free polyominoes of rank %d:" % n |
||
rank(n).each{|poly| puts text_representation(poly),""}</lang> |
rank(n).sort.each{|poly| puts text_representation(poly),""}</lang> |
||
{{out}} |
{{out}} |