A polyomino of size \$n\$ is a contiguous shape made from joining \$n\$ unit squares side by side. A domino is a size-2 polyomino.

A polydomino of size \$2n\$ is defined as a polyomino of size \$2n\$ which can be tiled with \$n\$ dominoes.

The following are some examples of polydominoes for \$n=3\$ (hexominoes).

. O O  |  . O . .  |  O O O .  |  O O O O O O
O O .  |  O O O O  |  O . O O  |
O O .  |  O . . .  |           |

The following are some hexominoes that are not polydominoes.

. O .  |  O . . .  |  O . O .
O O O  |  O O O O  |  O O O O
O O .  |  O . . .  |


Given a positive integer \$n\$, count the number of distinct polydominoes of size \$2n\$. Rotations and reflections are considered as the same shape. Different tilings of the same shape does not count either. You may take the value of \$2n\$ as input instead (you may assume the input is always even in this case).

The following shape has two ways to tile with dominoes, but it is counted only once just like other hexominoes.

. O O
O O .
O O .

The sequence is OEIS 056786.

Test cases

The following are the expected results for \$n=1 \cdots 9\$.

1, 4, 23, 211, 2227, 25824, 310242, 3818983, 47752136
  • \$\begingroup\$ What are dominoes? \$\endgroup\$
    – tsh
    Mar 23, 2021 at 5:12
  • 1
    \$\begingroup\$ @tsh A domino is a size-2 polyomino (two unit squares attached side by side). \$\endgroup\$
    – Bubbler
    Mar 23, 2021 at 5:14

2 Answers 2


Ruby, 266 250 242 bytes

->n,*z{j=(h=1,m=1i,-1,*r=[-m,0]).product h;(r.map{|c|j.map{|v,w|k=r+[v+=c,v+w];k|k==k&&(w=j.map{|y,q|(x=k.map{|v|y*[v,v.conj][q*q]}).map{|g|g-x.map(&:real).min-m*x.map(&:imag).min}.sort_by &:rect})-z==w&&z<<w[0]}};r,*z=z)until r[-n];z.size+1}

Try it online!

Not particularly original, I just recycled my solution to a similar problem, and changed some small details:

  • start with the basic domino (instead of single tile)
  • add 2 tiles on each step (instead of one)
  • check for reflection by using the complex conjugate (instead of only rotation using powers of i)
  • stop when reaching size 2n (instead of n) -> Accept 2n as input

How it works:

See the linked post for the full explanation. Basically, use complex numbers to make it easier.


43 seconds for n=5 (size 10) on TIO

Thanks Dingus for saving some bytes, the function is a mess and could probably be much shorter anyway if implemented properly.


JavaScript (ES10), 343 bytes

Expects \$2n\$ as input.


Try it online!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.