Jump to content

Free polyominoes enumeration: Difference between revisions

→‎{{header|Ruby}}: reduction of the unnecessary argument
(Added Ruby)
(→‎{{header|Ruby}}: reduction of the unnecessary argument)
Line 671:
end
 
def canonical(poly, polyomino, pattern)
polys = rotations_and_reflections(poly).map{|pl| translate2origin(pl)}
polys.each{|pl| pattern << pl}
polyomino << polys.min
end
 
Line 685 ⟶ 683:
def new_points(poly)
points = []
poly.each{|x,y| contiguous(x,y).each{|i,jpoint| points << [i,j]point}}
(points - poly).uniq
end
 
def new_polys(polys)
polyomino = Set.new
pattern = Set.new
polys.eacheach_with_object([]) do |poly, polyomino|
new_points(poly).each do |point|
next if pattern.include?(pl = translate2origin(poly + [point]))
polyomino << canonical(pl, polyomino,).each{|p| pattern) unless<< patternp}.include?(pl)min
end
end
polyomino.sort
end
 
Line 722 ⟶ 718:
n = ARGV[0] ? ARGV[0].to_i : 5
puts "\nAll free polyominoes of rank %d:" % n
rank(n).sort.each{|poly| puts text_representation(poly),""}</lang>
 
{{out}}
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.