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

replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

Mathematica: 86 bytes (or 82 bytes)

Thanks to the infinite @alephalpha @alephalpha for a clever array-based method:

Image@ArrayFlatten@Array[DiskMatrix@32~RotateLeft~32/.a_/;OddQ@+##:>1-Thread@a&,{5,5}]

Inside the array is an anonymous function, which uses a clever trick to add its arguments (+##) and determine whether the sum is odd. That boolean is used as the conditional to a pattern that replaces the whole 'white' tile with the transformed, 'black' tile. From there, ArrayFlatten joins together the tiles and Image displays them.

Note the use of the shorter Thread to replace Transpose. We can still save 4 bytes by using the transpose symbol instead.

Previous: 97 bytes (or 90 bytes)

Image@ArrayFlatten@Partition[
 Join@@Table[{#,1-Transpose@#}&@RotateLeft[DiskMatrix@32,32],{13}],5]

You can reduce the number of bytes by replacing Transpose@# with the superscript-t symbol (codepoint U+F3C7, shortcut ESCtrESC). In UTF-8 that brings the total to 90 bytes in 88 characters.

enter image description here

We start with DiskMatrix, which generates a binary matrix:

DiskMatrix@32 // Image

enter image description here

We then circular-shift the rows of the matrix to produce the unit cell for the tiling:

RotateLeft[DiskMatrix@32, 32] // Image

enter image description here

If the plane is a chessboard, these are the 'white' squares. For the 'black' squares, we need to invert the colors and rotate by 90 degrees. We can invert by subtracting from 1 (1 - 1 -> 0 and 1 - 0 -> 1), and rotate by taking the transpose:

Image /@ {#, 1 - Transpose@#} &@RotateLeft[DiskMatrix@32, 32]

enter image description here

If the dimensions of the image are even (like the minimum size, 4), then a tile on the right edge will be the same as the next one on the left edge. However, adding one tile to get an odd size (5) then concatenating the rows produces a regular alternating pattern.

This suggests that we can get the full image by wrapping a single row of alternating tiles with Partition. We use Table to make a list of 13 black/white tile pairs, and Join to flatten the list of pairs to a list of 26 tiles. Then we Partition the list into a 5 by 5 matrix of tiles (Partition discards the trailing 26th tile):

Map[Image] /@ 
 Partition[
 Join @@ Table[{#, 1 - #\[Transpose]} &@
 RotateLeft[DiskMatrix@32, 32], {13}], 5] // MatrixForm

enter image description here

Finally ArrayFlatten turns the matrix of tile matrices into a flat matrix, and Image displays the result.

Previous: 111 bytes

Image[ArrayFlatten[{{#, #}, {#, #}}] &[
 Join[#, Reverse@#, 2] &[
 Join[1 - Transpose@#, #] &@RotateLeft[DiskMatrix[32], 32]]]]

enter image description here

Mathematica: 86 bytes (or 82 bytes)

Thanks to the infinite @alephalpha for a clever array-based method:

Image@ArrayFlatten@Array[DiskMatrix@32~RotateLeft~32/.a_/;OddQ@+##:>1-Thread@a&,{5,5}]

Inside the array is an anonymous function, which uses a clever trick to add its arguments (+##) and determine whether the sum is odd. That boolean is used as the conditional to a pattern that replaces the whole 'white' tile with the transformed, 'black' tile. From there, ArrayFlatten joins together the tiles and Image displays them.

Note the use of the shorter Thread to replace Transpose. We can still save 4 bytes by using the transpose symbol instead.

Previous: 97 bytes (or 90 bytes)

Image@ArrayFlatten@Partition[
 Join@@Table[{#,1-Transpose@#}&@RotateLeft[DiskMatrix@32,32],{13}],5]

You can reduce the number of bytes by replacing Transpose@# with the superscript-t symbol (codepoint U+F3C7, shortcut ESCtrESC). In UTF-8 that brings the total to 90 bytes in 88 characters.

enter image description here

We start with DiskMatrix, which generates a binary matrix:

DiskMatrix@32 // Image

enter image description here

We then circular-shift the rows of the matrix to produce the unit cell for the tiling:

RotateLeft[DiskMatrix@32, 32] // Image

enter image description here

If the plane is a chessboard, these are the 'white' squares. For the 'black' squares, we need to invert the colors and rotate by 90 degrees. We can invert by subtracting from 1 (1 - 1 -> 0 and 1 - 0 -> 1), and rotate by taking the transpose:

Image /@ {#, 1 - Transpose@#} &@RotateLeft[DiskMatrix@32, 32]

enter image description here

If the dimensions of the image are even (like the minimum size, 4), then a tile on the right edge will be the same as the next one on the left edge. However, adding one tile to get an odd size (5) then concatenating the rows produces a regular alternating pattern.

This suggests that we can get the full image by wrapping a single row of alternating tiles with Partition. We use Table to make a list of 13 black/white tile pairs, and Join to flatten the list of pairs to a list of 26 tiles. Then we Partition the list into a 5 by 5 matrix of tiles (Partition discards the trailing 26th tile):

Map[Image] /@ 
 Partition[
 Join @@ Table[{#, 1 - #\[Transpose]} &@
 RotateLeft[DiskMatrix@32, 32], {13}], 5] // MatrixForm

enter image description here

Finally ArrayFlatten turns the matrix of tile matrices into a flat matrix, and Image displays the result.

Previous: 111 bytes

Image[ArrayFlatten[{{#, #}, {#, #}}] &[
 Join[#, Reverse@#, 2] &[
 Join[1 - Transpose@#, #] &@RotateLeft[DiskMatrix[32], 32]]]]

enter image description here

Mathematica: 86 bytes (or 82 bytes)

Thanks to the infinite @alephalpha for a clever array-based method:

Image@ArrayFlatten@Array[DiskMatrix@32~RotateLeft~32/.a_/;OddQ@+##:>1-Thread@a&,{5,5}]

Inside the array is an anonymous function, which uses a clever trick to add its arguments (+##) and determine whether the sum is odd. That boolean is used as the conditional to a pattern that replaces the whole 'white' tile with the transformed, 'black' tile. From there, ArrayFlatten joins together the tiles and Image displays them.

Note the use of the shorter Thread to replace Transpose. We can still save 4 bytes by using the transpose symbol instead.

Previous: 97 bytes (or 90 bytes)

Image@ArrayFlatten@Partition[
 Join@@Table[{#,1-Transpose@#}&@RotateLeft[DiskMatrix@32,32],{13}],5]

You can reduce the number of bytes by replacing Transpose@# with the superscript-t symbol (codepoint U+F3C7, shortcut ESCtrESC). In UTF-8 that brings the total to 90 bytes in 88 characters.

enter image description here

We start with DiskMatrix, which generates a binary matrix:

DiskMatrix@32 // Image

enter image description here

We then circular-shift the rows of the matrix to produce the unit cell for the tiling:

RotateLeft[DiskMatrix@32, 32] // Image

enter image description here

If the plane is a chessboard, these are the 'white' squares. For the 'black' squares, we need to invert the colors and rotate by 90 degrees. We can invert by subtracting from 1 (1 - 1 -> 0 and 1 - 0 -> 1), and rotate by taking the transpose:

Image /@ {#, 1 - Transpose@#} &@RotateLeft[DiskMatrix@32, 32]

enter image description here

If the dimensions of the image are even (like the minimum size, 4), then a tile on the right edge will be the same as the next one on the left edge. However, adding one tile to get an odd size (5) then concatenating the rows produces a regular alternating pattern.

This suggests that we can get the full image by wrapping a single row of alternating tiles with Partition. We use Table to make a list of 13 black/white tile pairs, and Join to flatten the list of pairs to a list of 26 tiles. Then we Partition the list into a 5 by 5 matrix of tiles (Partition discards the trailing 26th tile):

Map[Image] /@ 
 Partition[
 Join @@ Table[{#, 1 - #\[Transpose]} &@
 RotateLeft[DiskMatrix@32, 32], {13}], 5] // MatrixForm

enter image description here

Finally ArrayFlatten turns the matrix of tile matrices into a flat matrix, and Image displays the result.

Previous: 111 bytes

Image[ArrayFlatten[{{#, #}, {#, #}}] &[
 Join[#, Reverse@#, 2] &[
 Join[1 - Transpose@#, #] &@RotateLeft[DiskMatrix[32], 32]]]]

enter image description here

added alephalpha's method
Source Link
2012rcampion
  • 1.3k
  • 9
  • 13

Mathematica, 97: 86 bytes (or 9082 bytes)

Thanks to the infinite @alephalpha for a clever array-based method:

Image@ArrayFlatten@Array[DiskMatrix@32~RotateLeft~32/.a_/;OddQ@+##:>1-Thread@a&,{5,5}]

Inside the array is an anonymous function, which uses a clever trick to add its arguments (+##) and determine whether the sum is odd. That boolean is used as the conditional to a pattern that replaces the whole 'white' tile with the transformed, 'black' tile. From there, ArrayFlatten joins together the tiles and Image displays them.

Note the use of the shorter Thread to replace Transpose. We can still save 4 bytes by using the transpose symbol instead.

Previous: 97 bytes (or 90 bytes)

Image@ArrayFlatten@Partition[
 Join@@Table[{#,1-Transpose@#}&@RotateLeft[DiskMatrix@32,32],{13}],5]

You can reduce the number of bytes by replacing Transpose@# with the superscript-t symbol (codepoint U+F3C7, shortcut ESCtrESC). In UTF-8 that brings the total to 90 bytes in 88 characters.

enter image description here

We start with DiskMatrix, which generates a binary matrix:

DiskMatrix@32 // Image

enter image description here

We then circular-shift the rows of the matrix to produce the unit cell for the tiling:

RotateLeft[DiskMatrix@32, 32] // Image

enter image description here

If the plane is a chessboard, these are the 'white' squares. For the 'black' squares, we need to invert the colors and rotate by 90 degrees. We can invert by subtracting from 1 (1 - 1 -> 0 and 1 - 0 -> 1), and rotate by taking the transpose:

Image /@ {#, 1 - Transpose@#} &@RotateLeft[DiskMatrix@32, 32]

enter image description here

If the dimensions of the image are even (like the minimum size, 4), then a tile on the right edge will be the same as the next one on the left edge. However, adding one tile to get an odd size (5) then concatenating the rows produces a regular alternating pattern.

This suggests that we can get the full image by wrapping a single row of alternating tiles with Partition. We use Table to make a list of 13 black/white tile pairs, and Join to flatten the list of pairs to a list of 26 tiles. Then we Partition the list into a 5 by 5 matrix of tiles (Partition discards the trailing 26th tile):

Map[Image] /@ 
 Partition[
 Join @@ Table[{#, 1 - #\[Transpose]} &@
 RotateLeft[DiskMatrix@32, 32], {13}], 5] // MatrixForm

enter image description here

Finally ArrayFlatten turns the matrix of tile matrices into a flat matrix, and Image displays the result.

Previous: 111 bytes

Image[ArrayFlatten[{{#, #}, {#, #}}] &[
 Join[#, Reverse@#, 2] &[
 Join[1 - Transpose@#, #] &@RotateLeft[DiskMatrix[32], 32]]]]

enter image description here

Mathematica, 97 bytes (or 90 bytes)

Image@ArrayFlatten@Partition[
 Join@@Table[{#,1-Transpose@#}&@RotateLeft[DiskMatrix@32,32],{13}],5]

You can reduce the number of bytes by replacing Transpose@# with the superscript-t symbol (codepoint U+F3C7, shortcut ESCtrESC). In UTF-8 that brings the total to 90 bytes in 88 characters.

enter image description here

We start with DiskMatrix, which generates a binary matrix:

DiskMatrix@32 // Image

enter image description here

We then circular-shift the rows of the matrix to produce the unit cell for the tiling:

RotateLeft[DiskMatrix@32, 32] // Image

enter image description here

If the plane is a chessboard, these are the 'white' squares. For the 'black' squares, we need to invert the colors and rotate by 90 degrees. We can invert by subtracting from 1 (1 - 1 -> 0 and 1 - 0 -> 1), and rotate by taking the transpose:

Image /@ {#, 1 - Transpose@#} &@RotateLeft[DiskMatrix@32, 32]

enter image description here

If the dimensions of the image are even (like the minimum size, 4), then a tile on the right edge will be the same as the next one on the left edge. However, adding one tile to get an odd size (5) then concatenating the rows produces a regular alternating pattern.

This suggests that we can get the full image by wrapping a single row of alternating tiles with Partition. We use Table to make a list of 13 black/white tile pairs, and Join to flatten the list of pairs to a list of 26 tiles. Then we Partition the list into a 5 by 5 matrix of tiles (Partition discards the trailing 26th tile):

Map[Image] /@ 
 Partition[
 Join @@ Table[{#, 1 - #\[Transpose]} &@
 RotateLeft[DiskMatrix@32, 32], {13}], 5] // MatrixForm

enter image description here

Finally ArrayFlatten turns the matrix of tile matrices into a flat matrix, and Image displays the result.

Previous: 111 bytes

Image[ArrayFlatten[{{#, #}, {#, #}}] &[
 Join[#, Reverse@#, 2] &[
 Join[1 - Transpose@#, #] &@RotateLeft[DiskMatrix[32], 32]]]]

enter image description here

Mathematica: 86 bytes (or 82 bytes)

Thanks to the infinite @alephalpha for a clever array-based method:

Image@ArrayFlatten@Array[DiskMatrix@32~RotateLeft~32/.a_/;OddQ@+##:>1-Thread@a&,{5,5}]

Inside the array is an anonymous function, which uses a clever trick to add its arguments (+##) and determine whether the sum is odd. That boolean is used as the conditional to a pattern that replaces the whole 'white' tile with the transformed, 'black' tile. From there, ArrayFlatten joins together the tiles and Image displays them.

Note the use of the shorter Thread to replace Transpose. We can still save 4 bytes by using the transpose symbol instead.

Previous: 97 bytes (or 90 bytes)

Image@ArrayFlatten@Partition[
 Join@@Table[{#,1-Transpose@#}&@RotateLeft[DiskMatrix@32,32],{13}],5]

You can reduce the number of bytes by replacing Transpose@# with the superscript-t symbol (codepoint U+F3C7, shortcut ESCtrESC). In UTF-8 that brings the total to 90 bytes in 88 characters.

enter image description here

We start with DiskMatrix, which generates a binary matrix:

DiskMatrix@32 // Image

enter image description here

We then circular-shift the rows of the matrix to produce the unit cell for the tiling:

RotateLeft[DiskMatrix@32, 32] // Image

enter image description here

If the plane is a chessboard, these are the 'white' squares. For the 'black' squares, we need to invert the colors and rotate by 90 degrees. We can invert by subtracting from 1 (1 - 1 -> 0 and 1 - 0 -> 1), and rotate by taking the transpose:

Image /@ {#, 1 - Transpose@#} &@RotateLeft[DiskMatrix@32, 32]

enter image description here

If the dimensions of the image are even (like the minimum size, 4), then a tile on the right edge will be the same as the next one on the left edge. However, adding one tile to get an odd size (5) then concatenating the rows produces a regular alternating pattern.

This suggests that we can get the full image by wrapping a single row of alternating tiles with Partition. We use Table to make a list of 13 black/white tile pairs, and Join to flatten the list of pairs to a list of 26 tiles. Then we Partition the list into a 5 by 5 matrix of tiles (Partition discards the trailing 26th tile):

Map[Image] /@ 
 Partition[
 Join @@ Table[{#, 1 - #\[Transpose]} &@
 RotateLeft[DiskMatrix@32, 32], {13}], 5] // MatrixForm

enter image description here

Finally ArrayFlatten turns the matrix of tile matrices into a flat matrix, and Image displays the result.

Previous: 111 bytes

Image[ArrayFlatten[{{#, #}, {#, #}}] &[
 Join[#, Reverse@#, 2] &[
 Join[1 - Transpose@#, #] &@RotateLeft[DiskMatrix[32], 32]]]]

enter image description here

added explanation
Source Link
2012rcampion
  • 1.3k
  • 9
  • 13

Mathematica, 97 bytes (or 90 bytes)

Image@ArrayFlatten@Partition[
 Join@@Table[{#,1-Transpose@#}&@RotateLeft[DiskMatrix@32,32],{13}],5]

You can reduce the number of bytes by replacing Transpose@# with the superscript-t symbol (codepoint U+F3C7, shortcut ESCtrESC). In UTF-8 that brings the total to 90 bytes in 88 characters.

enter image description here

We start with DiskMatrix, which generates a binary matrix:

DiskMatrix@32 // Image

enter image description here

We then circular-shift the rows of the matrix to produce the unit cell for the tiling:

RotateLeft[DiskMatrix@32, 32] // Image

enter image description here

If the plane is a chessboard, these are the 'white' squares. For the 'black' squares, we need to invert the colors and rotate by 90 degrees. We can invert by subtracting from 1 (1 - 1 -> 0 and 1 - 0 -> 1), and rotate by taking the transpose:

Image /@ {#, 1 - Transpose@#} &@RotateLeft[DiskMatrix@32, 32]

enter image description here

If the dimensions of the image are even (like the minimum size, 4), then a tile on the right edge will be the same as the next one on the left edge. However, adding one tile to get an odd size (5) then concatenating the rows produces a regular alternating pattern.

This suggests that we can get the full image by wrapping a single row of alternating tiles with Partition. We use Table to make a list of 13 black/white tile pairs, and Join to flatten the list of pairs to a list of 26 tiles. Then we Partition the list into a 5 by 5 matrix of tiles (Partition discards the trailing 26th tile):

Map[Image] /@ 
 Partition[
 Join @@ Table[{#, 1 - #\[Transpose]} &@
 RotateLeft[DiskMatrix@32, 32], {13}], 5] // MatrixForm

enter image description here

Finally ArrayFlatten turns the matrix of tile matrices into a flat matrix, and Image displays the result.

Previous: 111 bytes

Image[ArrayFlatten[{{#, #}, {#, #}}] &[
 Join[#, Reverse@#, 2] &[
 Join[1 - Transpose@#, #] &@RotateLeft[DiskMatrix[32], 32]]]]

enter image description here

Mathematica, 97 bytes (or 90 bytes)

Image@ArrayFlatten@Partition[
 Join@@Table[{#,1-Transpose@#}&@RotateLeft[DiskMatrix@32,32],{13}],5]

You can reduce the number of bytes by replacing Transpose@# with the superscript-t symbol (codepoint U+F3C7, shortcut ESCtrESC). In UTF-8 that brings the total to 90 bytes in 88 characters.

enter image description here

Previous: 111 bytes

Image[ArrayFlatten[{{#, #}, {#, #}}] &[
 Join[#, Reverse@#, 2] &[
 Join[1 - Transpose@#, #] &@RotateLeft[DiskMatrix[32], 32]]]]

enter image description here

Mathematica, 97 bytes (or 90 bytes)

Image@ArrayFlatten@Partition[
 Join@@Table[{#,1-Transpose@#}&@RotateLeft[DiskMatrix@32,32],{13}],5]

You can reduce the number of bytes by replacing Transpose@# with the superscript-t symbol (codepoint U+F3C7, shortcut ESCtrESC). In UTF-8 that brings the total to 90 bytes in 88 characters.

enter image description here

We start with DiskMatrix, which generates a binary matrix:

DiskMatrix@32 // Image

enter image description here

We then circular-shift the rows of the matrix to produce the unit cell for the tiling:

RotateLeft[DiskMatrix@32, 32] // Image

enter image description here

If the plane is a chessboard, these are the 'white' squares. For the 'black' squares, we need to invert the colors and rotate by 90 degrees. We can invert by subtracting from 1 (1 - 1 -> 0 and 1 - 0 -> 1), and rotate by taking the transpose:

Image /@ {#, 1 - Transpose@#} &@RotateLeft[DiskMatrix@32, 32]

enter image description here

If the dimensions of the image are even (like the minimum size, 4), then a tile on the right edge will be the same as the next one on the left edge. However, adding one tile to get an odd size (5) then concatenating the rows produces a regular alternating pattern.

This suggests that we can get the full image by wrapping a single row of alternating tiles with Partition. We use Table to make a list of 13 black/white tile pairs, and Join to flatten the list of pairs to a list of 26 tiles. Then we Partition the list into a 5 by 5 matrix of tiles (Partition discards the trailing 26th tile):

Map[Image] /@ 
 Partition[
 Join @@ Table[{#, 1 - #\[Transpose]} &@
 RotateLeft[DiskMatrix@32, 32], {13}], 5] // MatrixForm

enter image description here

Finally ArrayFlatten turns the matrix of tile matrices into a flat matrix, and Image displays the result.

Previous: 111 bytes

Image[ArrayFlatten[{{#, #}, {#, #}}] &[
 Join[#, Reverse@#, 2] &[
 Join[1 - Transpose@#, #] &@RotateLeft[DiskMatrix[32], 32]]]]

enter image description here

used new tiling method
Source Link
2012rcampion
  • 1.3k
  • 9
  • 13
Loading
Source Link
2012rcampion
  • 1.3k
  • 9
  • 13
Loading

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