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

Return to Revisions

2 of 3
added 35 characters in body
Neil
  • 184.4k
  • 12
  • 76
  • 290

Charcoal, (削除) 120 (削除ここまで) 115 bytes

NθNηWS⊞υ⌕Aι#≔⟦⟧ζFθFηF2«≔EθEη0εFLυF§υμ¿λ§≔§ε+κν%+ιμη1§≔§ε+ιμ%+κνη1F2F2⊞ζ↨⭆⎇μ⮌εε⪫⎇ν⮌ξξω2»≔...ζ1υFυFζF¬&ικ⊞υ|ικ=×ばつθη

Try it online! Link is to verbose version of code. Takes inputs in the order width, height, newline-terminated polyomino and outputs a Charcoal boolean i.e. - only if the polyomino tiles the torus. Explanation:

NθNη

Input the size of the grid.

WS⊞υ⌕Aι#

Input the polyomino and convert it to a list of horizontal indices.

≔⟦⟧ζ

Start building up a list of polyomino placements.

FθFηF2«

Loop through each vertical and horizontal offset and direction.

≔EθEη0ε

Start with an empty grid.

FLυF§υμ

Loop over each cell of the polyomino...

¿λ§≔§ε+κν%+ιμη1§≔§ε+ιμ%+κνη1

... place the optionally transposed cell in the grid, but offset by the outer indices.

F2F2⊞ζ↨⭆⎇μ⮌εε⪫⎇ν⮌ξξω2

For each of four reflections of the grid, push the grid to the list of placements, represented as a base 2 integer (e.g. a grid with just the bottom right square filled would be 1 etc.)

»≔...ζ1υFυ

Start a breadth first search using the first placement.

Loop over each placement.

F¬&ικ

If this placement does not overlap the grid so far...

⊞υ|ικ

... then push the merged grid to the list of grids.

=×ばつθη

Check whether we pushed a completed grid. (This must be the last entry because any incomplete grid must by definition have fewer polyominoes and would therefore have been discovered earlier.)

Neil
  • 184.4k
  • 12
  • 76
  • 290

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