Print all colorings of a 3x3 grid

21

3

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

Filipe Teixeira

Posted 2015-06-08T17:55:27.710

Reputation: 405

@edc65 xnor made the edit, and Filipe approved it (after which I purged the comments). I just added tags. – Martin Ender – 2015-06-09T21:41:28.110

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 . – Stan Strum – 2018-04-14T21:30:43.210

Answers

16

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.

JohnE

Posted 2015-06-08T17:55:27.710

Reputation: 4 632

34

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

Martin Ender

Posted 2015-06-08T17:55:27.710

Reputation: 184 808

3upvoted for being the prettiest output – Filipe Teixeira – 2015-06-10T00:41:43.457

14

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>

edc65

Posted 2015-06-08T17:55:27.710

Reputation: 31 086

If you specify (ES6), you can replace .join('\n') with .join (literal newline, not space... stupid comment formatting) to save 3 bytes – Patrick Roberts – 2016-08-05T00:06:54.783

@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 – edc65 – 2016-08-05T04:55:54.253

6

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!

Oebele

Posted 2015-06-08T17:55:27.710

Reputation: 311

6

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

blabb

Posted 2015-06-08T17:55:27.710

Reputation: 219

6

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.

xnor

Posted 2015-06-08T17:55:27.710

Reputation: 115 687

4

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*

Martin Ender

Posted 2015-06-08T17:55:27.710

Reputation: 184 808

4

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!

nimi

Posted 2015-06-08T17:55:27.710

Reputation: 34 639

I think r x=sequence[x,x,x] does the same thing and is shorter. – Lynn – 2015-07-18T21:40:47.167

@Mauris: you're right. Edited my post. Thanks! – nimi – 2015-07-19T08:53:43.490

4

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.

Piccolo

Posted 2015-06-08T17:55:27.710

Reputation: 261

3

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.

Stephan Schinkel

Posted 2015-06-08T17:55:27.710

Reputation: 596

2

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!

Koishore Roy

Posted 2015-06-08T17:55:27.710

Reputation: 1 144

2

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

Kade

Posted 2015-06-08T17:55:27.710

Reputation: 7 463

2

Python 2, 81

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

dieter

Posted 2015-06-08T17:55:27.710

Reputation: 2 010

2

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)

clap

Posted 2015-06-08T17:55:27.710

Reputation: 834

2

Pyth, 11 bytes

V^`T9jbc3Nk

Try it here!

Thanks @Jakube :)

Beta Decay

Posted 2015-06-08T17:55:27.710

Reputation: 21 478

2

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(/.../){$&+$/}}*$/

daniero

Posted 2015-06-08T17:55:27.710

Reputation: 17 193

No need for tr, outputting 0 and 1 is fine. A few more suggestions 512.times{|i|$><<("%09b"%i).gsub(/.../){$&+$/}+$/} 50 bytes. – Level River St – 2016-09-11T23:04:25.227

2

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

Destructible Lemon

Posted 2015-06-08T17:55:27.710

Reputation: 5 908

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 – FlipTack – 2016-11-11T15:30:22.490

2

PHP, 55 bytes

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

uses 0 and 1. Run with -r.

Titus

Posted 2015-06-08T17:55:27.710

Reputation: 13 814

I just love the way I impletemented the separating newline :) – Titus – 2016-11-11T21:10:20.283

1

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

Armadillo

Posted 2015-06-08T17:55:27.710

Reputation: 11

1

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)

GoatInTheMachine

Posted 2015-06-08T17:55:27.710

Reputation: 463

1

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.

Cole Cameron

Posted 2015-06-08T17:55:27.710

Reputation: 1 013

1

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.

Lord Ratte

Posted 2015-06-08T17:55:27.710

Reputation: 111

1

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.

Emigna

Posted 2015-06-08T17:55:27.710

Reputation: 50 798

1

Perl, 56 55 bytes

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

Output:

000
000
000

100
000
000
...

Denis Ibaev

Posted 2015-06-08T17:55:27.710

Reputation: 876

0

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.

Erik the Outgolfer

Posted 2015-06-08T17:55:27.710

Reputation: 38 134

0

05AB1E, 15 bytes (non-competing)

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

Try it online!

Erik the Outgolfer

Posted 2015-06-08T17:55:27.710

Reputation: 38 134

0

J, 27 bytes

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

Try it online!

FrownyFrog

Posted 2015-06-08T17:55:27.710

Reputation: 3 112

The problem isn't restrictive on output format, so you could use echo _3]\"1#:i.512. – Bolce Bussiere – 2018-04-24T21:31:37.440

0

Tcl, 72 bytes

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

Try it online!

sergiol

Posted 2015-06-08T17:55:27.710

Reputation: 3 055

0

Japt, 16 15 bytes

#f4o8³_¤Åò3 ·+R

Try it online!

Oliver

Posted 2015-06-08T17:55:27.710

Reputation: 7 160

0

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!

Husnain Raza

Posted 2015-06-08T17:55:27.710

Reputation: 329

0

JavaScript (Node.js), 72 bytes

h=console.log;f=u=>h(u/4&1,u/2&1,u&1)|u/8;for(i=0;i<512;h``)f(f(f(i++)))

Try it online!

JavaScript (Node.js), 64 bytes

for(i=0;i<512;f(f(f(i++))))f=u=>console.log(u/4&1,u/2&1,u&1)|u/8

Try it online!

JavaScript (Node.js), 75 bytes

for(i=511;++i<1024;f(f(f(i))))f=u=>console.log(u.toString(2).slice(-3))|u/8

Try it online!

l4m2

Posted 2015-06-08T17:55:27.710

Reputation: 5 985

0

Perl 5, 48 bytes

say((sprintf"%09b",$_)=~s%...%$&$/%gr)for 0..511

Try it online!

Xcali

Posted 2015-06-08T17:55:27.710

Reputation: 7 671

0

Perl 5, 32 bytes

$_=("{.,#}"x3 .$/)x3;say<"$_\n">

Try it online!

Dom Hastings

Posted 2015-06-08T17:55:27.710

Reputation: 16 415

0

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

Denis Ibaev

Posted 2015-06-08T17:55:27.710

Reputation: 876