Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Can this polyomino tile the toroidal grid?

Inspired by certain puzzles on Flow Free: Warps.

Background

We all know that L-triominos can't tile the 3x3 board, and P-pentominos can't tile the 5x5 board. But the situation changes if we allow the board to wrap around in both dimensions:

L-triominos can tile 3x3 toroidal grid

The 3rd tile wraps around through all four edges.

┌ ┌─┐ ┐
 │ │3 
┌─┤ └─┐
│ │2 │
│ └─┬─┘
│1 │ 
└───┘ ┘

P-pentominos can tile the 5x5 toroidal grid

The 5th tile wraps around through all four edges.

┌ ┌───┬─┐ ┐
 │ │ │
┌─┘ │ └─┐
│ 1 │2 │
├─────┤ │
│ 3 │ │
│ ┌─┴─┬─┤
│ │ │ │
└─┬─┘ │ ╵
 │ 4 │5
└ └─────┘ ┘

Note that, in both cases, wrapping around in only one dimension doesn't allow such tiling.

In case the Unicode version is hard to read, here is the ASCII version:

3 2 3
1 2 2
1 1 3
5 1 1 2 5
1 1 1 2 2
3 3 3 2 2
3 3 4 4 5
5 4 4 4 5

Challenge

Given a polyomino and the size (width and height) of the toroidal grid, determine if the polyomino can tile the toroidal grid. The polyomino can be flipped and/or rotated.

A polyomino can be given in a variety of ways:

  • A list of coordinates representing each cell of polyomino
  • A 2D grid with on/off values of your choice (in this case, you cannot assume that the size of the grid defining the polyomino matches that of the toroidal grid)

The output (true or false) can be given using the truthy/falsy values in your language of choice, or two distinct values to indicate true/false respectively.

Standard rules apply. The shortest code in bytes wins.

Test cases

The polyomino is given as the collection of # symbols.

Truthy

# (singleton, a.k.a. monomino)
5x7 (or any size)
--------
## (domino)
4x3 (or any even size)
--------
#
## (L-triomino)
3x3 (as shown above)
--------
##
### (P-pentomino)
5x5 (as shown above)
--------
##
 ## (Z-tetromino)
4x4 (left as an exercise to the reader)
--------
###
#
# (V-pentomino)
5x5
--------
####
 #
 ### (a polyomino larger than the grid is possible)
4x4
--------
###
 ###
 ### (single polyomino can cover the entire grid, and can wrap multiple times)
3x3

Falsy

## (domino)
3x5 (or any odd sizes)
--------
###
#
1x8
--------
# #
### (U-pentomino)
5x5

Answer*

Draft saved
Draft discarded
Cancel

AltStyle によって変換されたページ (->オリジナル) /