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 Answer

deleted 254 characters in body
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

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

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

Try it online! 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§≔§ε⎇λ+κν+ιμ⎇λ+ιμ+κν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υ»FζFζ

Start a breadth first search using the first placement.

Loop over each placementthe pairs of placements.

F¬&ικ

If this placement doespair do not overlap the grid so far...

⊞υ|ικ⊞ζ|ικ

... then push the merged gridpair to the list of gridsplacements.

=×ばつθη=×ばつθη

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.)

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.)

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

NθNηWS⊞υ⌕Aι#≔⟦⟧ζFθFηF2«≔EθEη0εFLυF§υμ§≔§ε⎇λ+κν+ιμ⎇λ+ιμ+κν1F2F2⊞ζ⍘⭆⎇μ⮌εε⪫⎇ν⮌ξξω2»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

... 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.)

»FζFζ

Start a breadth first search over the pairs of placements.

F¬&ικ

If this pair do not overlap...

⊞ζ|ικ

... then push the merged pair to the list of placements.

=×ばつθη

Check whether we pushed a completed grid.

added 35 characters in body
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

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

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

Try it online! 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⊞ζE⎇μ⮌εε↨⎇ν⮌ξξ2F2F2⊞ζ↨⭆⎇μ⮌εε⪫⎇ν⮌ξξω2

For each of four reflections of the grid, push the grid to the list of placements, but with the rows convertedrepresented as if they were 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¬⊙ι&λ§κμF¬&ικ

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

⊞υEι|μ§κν⊞υ|ικ

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

=⌊⊟υ⊖X2η=×ばつθη

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.)

Charcoal, 120 bytes

NθNηWS⊞υ⌕Aι#≔⟦⟧ζFθFηF2«≔EθEη0εFLυF§υμ¿λ§≔§ε+κν%+ιμη1§≔§ε+ιμ%+κνη1F2F2⊞ζE⎇μ⮌εε↨⎇ν⮌ξξ2»≔...ζ1υFυFζF¬⊙ι&λ§κμ⊞υEι|μ§κν=⌊⊟υ⊖X2η

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⊞ζE⎇μ⮌εε↨⎇ν⮌ξξ2

For each of four reflections of the grid, push the grid to the list of placements, but with the rows converted as if they were a base 2 integer.

»≔...ζ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...

⊞υEι|μ§κν

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

=⌊⊟υ⊖X2η

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.)

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.)

Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Charcoal, 120 bytes

NθNηWS⊞υ⌕Aι#≔⟦⟧ζFθFηF2«≔EθEη0εFLυF§υμ¿λ§≔§ε+κν%+ιμη1§≔§ε+ιμ%+κνη1F2F2⊞ζE⎇μ⮌εε↨⎇ν⮌ξξ2»≔...ζ1υFυFζF¬⊙ι&λ§κμ⊞υEι|μ§κν=⌊⊟υ⊖X2η

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⊞ζE⎇μ⮌εε↨⎇ν⮌ξξ2

For each of four reflections of the grid, push the grid to the list of placements, but with the rows converted as if they were a base 2 integer.

»≔...ζ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...

⊞υEι|μ§κν

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

=⌊⊟υ⊖X2η

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.)

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