21
\$\begingroup\$

You have a 3x3 grid. Each cell can be colored black or white. Display all 512 of these colorings. Fewest bytes wins.

You can display the grids in any formation as long as they are visually separated and the spacing looks regular. You may use ASCII art or images. Any two distinct visible symbols or colors can be used for black and white. Any whitespace is fine as long as the result is visually correct.

Example output:

...
...
...

...
...
..X

...
...
.X.

...
...
.XX

...
...
X..

...
...
X.X

...
...
XX.

...
...
XXX

...
..X
...

...
..X
..X

...
..X
.X.

...
..X
.XX

...
..X
X..

...
..X
X.X

...
..X
XX.

...
..X
XXX

...
.X.
...

...
.X.
..X

...
.X.
.X.

...
.X.
.XX

...
.X.
X..

...
.X.
X.X

...
.X.
XX.

...
.X.
XXX

...
.XX
...

...
.XX
..X

...
.XX
.X.

...
.XX
.XX

...
.XX
X..

...
.XX
X.X

...
.XX
XX.

...
.XX
XXX

...
X..
...

...
X..
..X

...
X..
.X.

...
X..
.XX

...
X..
X..

...
X..
X.X

...
X..
XX.

...
X..
XXX

...
X.X
...

...
X.X
..X

...
X.X
.X.

...
X.X
.XX

...
X.X
X..

...
X.X
X.X

...
X.X
XX.

...
X.X
XXX

...
XX.
...

...
XX.
..X

...
XX.
.X.

...
XX.
.XX

...
XX.
X..

...
XX.
X.X

...
XX.
XX.

...
XX.
XXX

...
XXX
...

...
XXX
..X

...
XXX
.X.

...
XXX
.XX

...
XXX
X..

...
XXX
X.X

...
XXX
XX.

...
XXX
XXX

..X
...
...

..X
...
..X

..X
...
.X.

..X
...
.XX

..X
...
X..

..X
...
X.X

..X
...
XX.

..X
...
XXX

..X
..X
...

..X
..X
..X

..X
..X
.X.

..X
..X
.XX

..X
..X
X..

..X
..X
X.X

..X
..X
XX.

..X
..X
XXX

..X
.X.
...

..X
.X.
..X

..X
.X.
.X.

..X
.X.
.XX

..X
.X.
X..

..X
.X.
X.X

..X
.X.
XX.

..X
.X.
XXX

..X
.XX
...

..X
.XX
..X

..X
.XX
.X.

..X
.XX
.XX

..X
.XX
X..

..X
.XX
X.X

..X
.XX
XX.

..X
.XX
XXX

..X
X..
...

..X
X..
..X

..X
X..
.X.

..X
X..
.XX

..X
X..
X..

..X
X..
X.X

..X
X..
XX.

..X
X..
XXX

..X
X.X
...

..X
X.X
..X

..X
X.X
.X.

..X
X.X
.XX

..X
X.X
X..

..X
X.X
X.X

..X
X.X
XX.

..X
X.X
XXX

..X
XX.
...

..X
XX.
..X

..X
XX.
.X.

..X
XX.
.XX

..X
XX.
X..

..X
XX.
X.X

..X
XX.
XX.

..X
XX.
XXX

..X
XXX
...

..X
XXX
..X

..X
XXX
.X.

..X
XXX
.XX

..X
XXX
X..

..X
XXX
X.X

..X
XXX
XX.

..X
XXX
XXX

.X.
...
...

.X.
...
..X

.X.
...
.X.

.X.
...
.XX

.X.
...
X..

.X.
...
X.X

.X.
...
XX.

.X.
...
XXX

.X.
..X
...

.X.
..X
..X

.X.
..X
.X.

.X.
..X
.XX

.X.
..X
X..

.X.
..X
X.X

.X.
..X
XX.

.X.
..X
XXX

.X.
.X.
...

.X.
.X.
..X

.X.
.X.
.X.

.X.
.X.
.XX

.X.
.X.
X..

.X.
.X.
X.X

.X.
.X.
XX.

.X.
.X.
XXX

.X.
.XX
...

.X.
.XX
..X

.X.
.XX
.X.

.X.
.XX
.XX

.X.
.XX
X..

.X.
.XX
X.X

.X.
.XX
XX.

.X.
.XX
XXX

.X.
X..
...

.X.
X..
..X

.X.
X..
.X.

.X.
X..
.XX

.X.
X..
X..

.X.
X..
X.X

.X.
X..
XX.

.X.
X..
XXX

.X.
X.X
...

.X.
X.X
..X

.X.
X.X
.X.

.X.
X.X
.XX

.X.
X.X
X..

.X.
X.X
X.X

.X.
X.X
XX.

.X.
X.X
XXX

.X.
XX.
...

.X.
XX.
..X

.X.
XX.
.X.

.X.
XX.
.XX

.X.
XX.
X..

.X.
XX.
X.X

.X.
XX.
XX.

.X.
XX.
XXX

.X.
XXX
...

.X.
XXX
..X

.X.
XXX
.X.

.X.
XXX
.XX

.X.
XXX
X..

.X.
XXX
X.X

.X.
XXX
XX.

.X.
XXX
XXX

.XX
...
...

.XX
...
..X

.XX
...
.X.

.XX
...
.XX

.XX
...
X..

.XX
...
X.X

.XX
...
XX.

.XX
...
XXX

.XX
..X
...

.XX
..X
..X

.XX
..X
.X.

.XX
..X
.XX

.XX
..X
X..

.XX
..X
X.X

.XX
..X
XX.

.XX
..X
XXX

.XX
.X.
...

.XX
.X.
..X

.XX
.X.
.X.

.XX
.X.
.XX

.XX
.X.
X..

.XX
.X.
X.X

.XX
.X.
XX.

.XX
.X.
XXX

.XX
.XX
...

.XX
.XX
..X

.XX
.XX
.X.

.XX
.XX
.XX

.XX
.XX
X..

.XX
.XX
X.X

.XX
.XX
XX.

.XX
.XX
XXX

.XX
X..
...

.XX
X..
..X

.XX
X..
.X.

.XX
X..
.XX

.XX
X..
X..

.XX
X..
X.X

.XX
X..
XX.

.XX
X..
XXX

.XX
X.X
...

.XX
X.X
..X

.XX
X.X
.X.

.XX
X.X
.XX

.XX
X.X
X..

.XX
X.X
X.X

.XX
X.X
XX.

.XX
X.X
XXX

.XX
XX.
...

.XX
XX.
..X

.XX
XX.
.X.

.XX
XX.
.XX

.XX
XX.
X..

.XX
XX.
X.X

.XX
XX.
XX.

.XX
XX.
XXX

.XX
XXX
...

.XX
XXX
..X

.XX
XXX
.X.

.XX
XXX
.XX

.XX
XXX
X..

.XX
XXX
X.X

.XX
XXX
XX.

.XX
XXX
XXX

X..
...
...

X..
...
..X

X..
...
.X.

X..
...
.XX

X..
...
X..

X..
...
X.X

X..
...
XX.

X..
...
XXX

X..
..X
...

X..
..X
..X

X..
..X
.X.

X..
..X
.XX

X..
..X
X..

X..
..X
X.X

X..
..X
XX.

X..
..X
XXX

X..
.X.
...

X..
.X.
..X

X..
.X.
.X.

X..
.X.
.XX

X..
.X.
X..

X..
.X.
X.X

X..
.X.
XX.

X..
.X.
XXX

X..
.XX
...

X..
.XX
..X

X..
.XX
.X.

X..
.XX
.XX

X..
.XX
X..

X..
.XX
X.X

X..
.XX
XX.

X..
.XX
XXX

X..
X..
...

X..
X..
..X

X..
X..
.X.

X..
X..
.XX

X..
X..
X..

X..
X..
X.X

X..
X..
XX.

X..
X..
XXX

X..
X.X
...

X..
X.X
..X

X..
X.X
.X.

X..
X.X
.XX

X..
X.X
X..

X..
X.X
X.X

X..
X.X
XX.

X..
X.X
XXX

X..
XX.
...

X..
XX.
..X

X..
XX.
.X.

X..
XX.
.XX

X..
XX.
X..

X..
XX.
X.X

X..
XX.
XX.

X..
XX.
XXX

X..
XXX
...

X..
XXX
..X

X..
XXX
.X.

X..
XXX
.XX

X..
XXX
X..

X..
XXX
X.X

X..
XXX
XX.

X..
XXX
XXX

X.X
...
...

X.X
...
..X

X.X
...
.X.

X.X
...
.XX

X.X
...
X..

X.X
...
X.X

X.X
...
XX.

X.X
...
XXX

X.X
..X
...

X.X
..X
..X

X.X
..X
.X.

X.X
..X
.XX

X.X
..X
X..

X.X
..X
X.X

X.X
..X
XX.

X.X
..X
XXX

X.X
.X.
...

X.X
.X.
..X

X.X
.X.
.X.

X.X
.X.
.XX

X.X
.X.
X..

X.X
.X.
X.X

X.X
.X.
XX.

X.X
.X.
XXX

X.X
.XX
...

X.X
.XX
..X

X.X
.XX
.X.

X.X
.XX
.XX

X.X
.XX
X..

X.X
.XX
X.X

X.X
.XX
XX.

X.X
.XX
XXX

X.X
X..
...

X.X
X..
..X

X.X
X..
.X.

X.X
X..
.XX

X.X
X..
X..

X.X
X..
X.X

X.X
X..
XX.

X.X
X..
XXX

X.X
X.X
...

X.X
X.X
..X

X.X
X.X
.X.

X.X
X.X
.XX

X.X
X.X
X..

X.X
X.X
X.X

X.X
X.X
XX.

X.X
X.X
XXX

X.X
XX.
...

X.X
XX.
..X

X.X
XX.
.X.

X.X
XX.
.XX

X.X
XX.
X..

X.X
XX.
X.X

X.X
XX.
XX.

X.X
XX.
XXX

X.X
XXX
...

X.X
XXX
..X

X.X
XXX
.X.

X.X
XXX
.XX

X.X
XXX
X..

X.X
XXX
X.X

X.X
XXX
XX.

X.X
XXX
XXX

XX.
...
...

XX.
...
..X

XX.
...
.X.

XX.
...
.XX

XX.
...
X..

XX.
...
X.X

XX.
...
XX.

XX.
...
XXX

XX.
..X
...

XX.
..X
..X

XX.
..X
.X.

XX.
..X
.XX

XX.
..X
X..

XX.
..X
X.X

XX.
..X
XX.

XX.
..X
XXX

XX.
.X.
...

XX.
.X.
..X

XX.
.X.
.X.

XX.
.X.
.XX

XX.
.X.
X..

XX.
.X.
X.X

XX.
.X.
XX.

XX.
.X.
XXX

XX.
.XX
...

XX.
.XX
..X

XX.
.XX
.X.

XX.
.XX
.XX

XX.
.XX
X..

XX.
.XX
X.X

XX.
.XX
XX.

XX.
.XX
XXX

XX.
X..
...

XX.
X..
..X

XX.
X..
.X.

XX.
X..
.XX

XX.
X..
X..

XX.
X..
X.X

XX.
X..
XX.

XX.
X..
XXX

XX.
X.X
...

XX.
X.X
..X

XX.
X.X
.X.

XX.
X.X
.XX

XX.
X.X
X..

XX.
X.X
X.X

XX.
X.X
XX.

XX.
X.X
XXX

XX.
XX.
...

XX.
XX.
..X

XX.
XX.
.X.

XX.
XX.
.XX

XX.
XX.
X..

XX.
XX.
X.X

XX.
XX.
XX.

XX.
XX.
XXX

XX.
XXX
...

XX.
XXX
..X

XX.
XXX
.X.

XX.
XXX
.XX

XX.
XXX
X..

XX.
XXX
X.X

XX.
XXX
XX.

XX.
XXX
XXX

XXX
...
...

XXX
...
..X

XXX
...
.X.

XXX
...
.XX

XXX
...
X..

XXX
...
X.X

XXX
...
XX.

XXX
...
XXX

XXX
..X
...

XXX
..X
..X

XXX
..X
.X.

XXX
..X
.XX

XXX
..X
X..

XXX
..X
X.X

XXX
..X
XX.

XXX
..X
XXX

XXX
.X.
...

XXX
.X.
..X

XXX
.X.
.X.

XXX
.X.
.XX

XXX
.X.
X..

XXX
.X.
X.X

XXX
.X.
XX.

XXX
.X.
XXX

XXX
.XX
...

XXX
.XX
..X

XXX
.XX
.X.

XXX
.XX
.XX

XXX
.XX
X..

XXX
.XX
X.X

XXX
.XX
XX.

XXX
.XX
XXX

XXX
X..
...

XXX
X..
..X

XXX
X..
.X.

XXX
X..
.XX

XXX
X..
X..

XXX
X..
X.X

XXX
X..
XX.

XXX
X..
XXX

XXX
X.X
...

XXX
X.X
..X

XXX
X.X
.X.

XXX
X.X
.XX

XXX
X.X
X..

XXX
X.X
X.X

XXX
X.X
XX.

XXX
X.X
XXX

XXX
XX.
...

XXX
XX.
..X

XXX
XX.
.X.

XXX
XX.
.XX

XXX
XX.
X..

XXX
XX.
X.X

XXX
XX.
XX.

XXX
XX.
XXX

XXX
XXX
...

XXX
XXX
..X

XXX
XXX
.X.

XXX
XXX
.XX

XXX
XXX
X..

XXX
XXX
X.X

XXX
XXX
XX.

XXX
XXX
XXX
\$\endgroup\$
  • \$\begingroup\$ @edc65 xnor made the edit, and Filipe approved it (after which I purged the comments). I just added tags. \$\endgroup\$ – Martin Ender Jun 9 '15 at 21:41
  • \$\begingroup\$ Can we move the example to a PasteBin? It’s anemic to scroll as of right now. Besides, this is just the power set of the input squared, divided into lines of the input where the 1s and 0s are replaced by X and . \$\endgroup\$ – Stan Strum Apr 14 '18 at 21:30

34 Answers 34

16
\$\begingroup\$

K, 11 bytes

(3 3#)'!9#2

Output example:

((0 0 0
  0 0 0
  0 0 0)
 (0 0 0
  0 0 0
  0 0 1)
 (0 0 0
  0 0 0
  0 1 0)
 (0 0 0
  0 0 0
  0 1 1)
…

This is K's native prettyprinted representation of a list of matrices, which I think is sufficient for the problem spec. Each matrix is delimited by an enclosing set of parentheses.

And a quick sanity check to demonstrate that 512 matrices are constructed:

  #(3 3#)'!9#2
512

Very straightforward. Most of the work is in the !. First we generate a 9-long vector of 2s using "take" (9#2). Then, we make use of the "odometer" monadic form of !- a few examples illustrate its behavior:

  !2 2
(0 0
 0 1
 1 0
 1 1)
  !2 3
(0 0
 0 1
 0 2
 1 0
 1 1
 1 2)
  !2 2 2
(0 0 0
 0 0 1
 0 1 0
 0 1 1
 1 0 0
 1 0 1
 1 1 0
 1 1 1)

Then simply do a 3x3 reshape ((3 3#)) of each (') of the 9-length 0/1 vectors.

\$\endgroup\$
34
\$\begingroup\$

Mathematica, 25 bytes

Image/@{0,1}~Tuples~{3,3}

Gives an array with all the grids as images, which is also directly displayed on screen:

enter image description here

(Cropped so as not to blow up the post unnecessarily.)

\$\endgroup\$
  • 3
    \$\begingroup\$ upvoted for being the prettiest output \$\endgroup\$ – Filipe Teixeira Jun 10 '15 at 0:41
13
\$\begingroup\$

JavaScript, 77 80

Revised after the revision of the OP. Now we have a question, so here is an answer.

Run the snippet in any browser to test.

// Test: redefine console to have output inside the snippet

console = { log: function(x) { O.textContent+=x+'\n\n';} }

// Solution: 77 chars (note, distinct outputs to console are automatically separed)
  
for(i=511;++i<1024;)console.log(i.toString(2).slice(1).match(/.../g).join`
`)
<pre id=O></pre>

Old post: graphic display in a browser, with javascript and canvas. ~300 byte of code (can be made shorter).

Run the snippet below.

d=8, // Min block size
C.width=d*64,C.height=d*128,
T=C.getContext('2d')

for(i=0;i<512;i++)
{
  bx=4*(i/32|0)
  by=4*(i%32)
  for(b=1,j=0;j<9;j++,b+=b)    
  {
    if(b&i) 
      x=j/3|0, y=j%3, T.fillRect((bx+x)*d,(by+y)*d,d,d);
  }
  T.strokeRect(bx*d,by*d,d*3,d*3);
}
<canvas id=C></canvas>

\$\endgroup\$
  • \$\begingroup\$ If you specify (ES6), you can replace .join('\n') with .join` ` (literal newline, not space... stupid comment formatting) to save 3 bytes \$\endgroup\$ – Patrick Roberts Aug 5 '16 at 0:06
  • \$\begingroup\$ @PatrickRoberts yes, template string was already implemented in Firefox 14 months ago, but I was not aware of that. Edit the code after so much time is a little necrobumping \$\endgroup\$ – edc65 Aug 5 '16 at 4:55
6
\$\begingroup\$

Matlab, 33

reshape(dec2bin(0:511,9)',3,3,[])

Was kind of fiddly to get the dimensions correct, but I am very happy with the result!

\$\endgroup\$
6
\$\begingroup\$

POWERSHELL - 65

0..511|%{[convert]::ToString($_,2).padleft(9,'0')-split"(.{3})"}

result

000

000

000


000

000

001


000

000

010


000

000

011

confirmation

(0..511|%{[convert]::ToString($_,2).padleft(9,'0')-split"(.{3})"} | measure -Line).lines/3

512

edit inspired by the mathematica answer's display of results-617

Add-Type -AssemblyName System.Drawing
$a=new-object System.Drawing.Bitmap 992,496
$g=[Drawing.Graphics]::FromImage($a)
$b=@{};$y=@{};$i=$c=$d=$z=$k=$l=$m=0;
0..511|%{$y[$d++]=[convert]::ToString($_,2).padleft(9,'0')}
while($m-lt480){while($l-lt496){for($z=($m+0);$z-lt($m+32);$z++){
      $y[$z].tochararray()|%{if($_-eq"0"){$b[$i++]=[Drawing.Brushes]::Black}
        else{$b[$i++]=[Drawing.Brushes]::White}
      }
      for($j=($l+0);$j-lt($l+30);$j+=10){
        ($k+0),($k+10),($k+20)|%{$g.FillRectangle($b[$c++],$_,$j,10,10)}
      }$k+=31
    }$k=0;$l+=31;$m+=32
  }
}$a.save("$HOME/3X3_Grid.png")

enter image description here

\$\endgroup\$
6
\$\begingroup\$

Python 2, 49 bytes

i=2048;exec"print bin(i/4)[i%4*3+3:][:3];i+=1;"*i

Split the binary expansion of i. The length-10 binary values 512 through 1023 are used, cutting off the initial 1 (and prefix 0b). These are split into chunks of 3 as windows [3:6], [6:9], [9:12], and [12:15], with the last one blank to make a blank line. Iterating over the four slices is collapsed with the outer loop of counting through 512 numbers with the divmod trick.

\$\endgroup\$
4
\$\begingroup\$

CJam, 12 bytes

2,9m*3f/N*N*

Test it here.

Uses 0 and 1 as the distinct characters.

Explanation

2,  e# Push [0 1].
9m* e# Generate all 9-tuples of 0s and 1s.
3f/ e# Split each 9-tuple into 3 subarrays of length 3.
N*  e# Join all those grids with newlines.
N*  e# Put newlines between all the length-3 arrays.

An alternative (still 12 byte) solution is

2,3m*3m*N*N*
\$\endgroup\$
4
\$\begingroup\$

Ruby, 86 bytes

0.upto(511).map{|i|i.to_s(2).rjust(9,'0')}.each{|j|p j[0..2];p j[3..5];p j[6..8];puts}

Mine prints with quotes because p is shorter than puts, but it does still fit the rules.

\$\endgroup\$
4
\$\begingroup\$

Haskell, 57 54 bytes

r x=sequence[x,x,x]
u=unlines
f=putStr$u$map u$r$r".X"

f gives the same output as in the challenge description, i.e. it starts with

...
...
...

...
...
..X

...
...
.X.

Edit: @Mauris found 3 bytes to save. Thanks!

\$\endgroup\$
  • \$\begingroup\$ I think r x=sequence[x,x,x] does the same thing and is shorter. \$\endgroup\$ – Lynn Jul 18 '15 at 21:40
  • \$\begingroup\$ @Mauris: you're right. Edited my post. Thanks! \$\endgroup\$ – nimi Jul 19 '15 at 8:53
3
\$\begingroup\$

C# - 111

for(int i=0;i<512;i++)Console.WriteLine(Regex.Replace(Convert.ToString(i,2).PadLeft(9,'0'),"(.{3})","$1\r\n"));

Converts every int to its binary representation and splits every 3 chars.

\$\endgroup\$
2
\$\begingroup\$

Python 2, 95 Bytes

Distinct characters are 0 and 1, each block is separated by \n\n.

n='\n';print(n+n).join(y[:3]+n+y[3:6]+n+y[-3:]for y in[bin(x)[2:].zfill(9)for x in range(512)])
\$\endgroup\$
2
\$\begingroup\$

Python 2, 81

import re
for i in range(512):print re.sub('(.{3})','\\1\n',bin(i)[2:].zfill(9))
\$\endgroup\$
2
\$\begingroup\$

Ruby, 92 bytes

0.upto(511){|i|("%09d"%i.to_s(2)).scan(/.{3}/).map{|j|j.scan(/./)}.map{|j|puts j.join};puts}

Counts in 0s and 1s, and each block is separated by an empty line (\n\n)

\$\endgroup\$
2
\$\begingroup\$

Ruby, 68 bytes

Prints the exact same output as the example given in the question

puts (0..511).map{|i|("%09b"%i).tr("01",".X").gsub(/.../){$&+$/}}*$/
\$\endgroup\$
  • \$\begingroup\$ No need for tr, outputting 0 and 1 is fine. A few more suggestions 512.times{|i|$><<("%09b"%i).gsub(/.../){$&+$/}+$/} 50 bytes. \$\endgroup\$ – Level River St Sep 11 '16 at 23:04
2
\$\begingroup\$

Python 3, 80 bytes

for i in range(512):print("\n".join(format(i,'09b')[j:j+3]for j in(0,3,6)),"\n")

I managed to outgolf someone :)

\$\endgroup\$
  • \$\begingroup\$ Save a byte using a while loop: i=512 newline while i:print("\n".join(format(i,'09b')[j:j+3]for j in(0,3,6)),"\n");i-=1 \$\endgroup\$ – FlipTack Nov 11 '16 at 15:30
2
\$\begingroup\$

PHP, 55 bytes

for(;$c<512;)echo chunk_split(sprintf("%09b ",$c++),3);

uses 0 and 1. Run with -r.

\$\endgroup\$
  • \$\begingroup\$ I just love the way I impletemented the separating newline :) \$\endgroup\$ – Titus Nov 11 '16 at 21:10
2
\$\begingroup\$

Pyth, 11 bytes

V^`T9jbc3Nk

Try it here!

Thanks @Jakube :)

\$\endgroup\$
2
\$\begingroup\$

Python 2, 56 bytes

from itertools import*
print set(combinations('X.'*9,9))

Try it online!

Returns the 512 configurations as a set object in python. Refer to ungolfed version to make output more readable.

Ungolfed Version to make output more readable:

Python 2, 121 bytes

from itertools import*
for i in set(combinations('X.'*9,9)):
	for j in range(3):print''.join(list(i))[j*3:(j*3)+3]
	print

Try it online!

\$\endgroup\$
1
\$\begingroup\$

C - 97 bytes

i;main(j){for(;i++<512;)for(j=0;j++<13;)putchar(j%4&&j<13?i%(1<<j-j/4)>(1<<j-j/4-1)-1?88:46:10);}

Basically prints the example output from the original question.

\$\endgroup\$
1
\$\begingroup\$

Swift 2, 92 bytes

Int to binary string in Swift takes up too many chars so I just use two nested loops...

var s="";for x in 0..<512{(0..<9).map{s+=($0%3==0 ?"\n":"")+"\(x>>$0&1)"};s+="\n-"};print(s)
\$\endgroup\$
1
\$\begingroup\$

Prolog (SWI), 98 bytes

Output is a list of 3x3 matrices containing the elements 0 and 1.

r([]).
r([H|T]):-between(0,1,H),r(T).
p(Y):-Z=[[_,_,_],[_,_,_],[_,_,_]],findall(Z,maplist(r,Z),Y).

Online interpreter

I feel like the matrix generation could be shorter.
It should be possible to fit the between in a forall or something similar, but I can't figure out how.

Golfing tips appreciated.

\$\endgroup\$
1
\$\begingroup\$

Perl, 56 55 bytes

print$_/9&1<<$_%9?1:0,$/x(!(++$_%3)+!($_%9))for+0..4607

Output:

000
000
000

100
000
000
...
\$\endgroup\$
1
\$\begingroup\$

Python 3, 123 121 109 103 bytes

Here is my old one:

import itertools
[print(a+b+c,d+e+f,g+h+i,'\n',sep='\n') for a,b,c,d,e,f,g,h,i in itertools.product(['X','.'],repeat=9)]

And here is my new one:

import itertools as i
[print(a[:3],a[3:6],a[6:],'\n',sep='\n') for a in i.product(['X','.'],repeat=9)]

This prints extra characters but the OP said ASCII art is allowed which implies multiple characters are fine.

\$\endgroup\$
1
\$\begingroup\$

Python 3, 74 bytes

i=512;b="\n"
while i:i-=1;a=format(i,'09b');print(a[:3]+b+a[3:6]+b+a[6:],b)

Just a little shorter than Destructible Lemon's answer

\$\endgroup\$
0
\$\begingroup\$

Perl, 52 bytes

printf+("%03b
"x3).$/,$_&7,$_/8&7,$_>>6&7 for 0..511

or 54 bytes:

print map$_.$/,sprintf('%09b',$_)=~/.../g,''for 0..511

or Perl 5.14+, 48 bytes:

say sprintf('%09b',$_)=~s/.../$&\n/gr for 0..511
\$\endgroup\$
0
\$\begingroup\$

Jelly, 17 bytes (non-competing)

512+ḶBḊ€s€3Y€j“¶¶

Try it online!

Uses 01. Because of a bug in , I had to use “¶¶ instead of ⁾¶¶, because otherwise, instead of two newlines, two pilcrows would have showed up in the output. As you can see, though, that didn't cost me any bytes at all.

K beats this, so this must be further golfed down.

\$\endgroup\$
0
\$\begingroup\$

05AB1E, 15 bytes (non-competing)

žAFNžA+b¦3ô»,¶?

Try it online!

\$\endgroup\$
0
\$\begingroup\$

J, 27 bytes

echo@<"2'.X'{~_3]\"1#:i.512

Try it online!

\$\endgroup\$
  • \$\begingroup\$ The problem isn't restrictive on output format, so you could use echo _3]\"1#:i.512. \$\endgroup\$ – Bolce Bussiere Apr 24 '18 at 21:31
0
\$\begingroup\$

Tcl, 72 bytes

time {puts [regsub -all (...) [format %09b [expr [incr i]-1]] \&\n]} 512

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Failed outgolf: tio.run/… \$\endgroup\$ – sergiol Apr 14 '18 at 21:37
0
\$\begingroup\$

Python 2, 114 bytes

from itertools import *
for i in product(".X",repeat=9):
    i="".join(i);print i[0:3]+"\n"+i[3:6]+"\n"+i[6:]+"\n"

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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