I constructed this some time ago:
gc=:0&(,.~),1:,.~|.
GC=: 3 : 'gc^:(<:y.) ,.0 1'
NB. GC d is d-dimensional binary reflected Gray code
GC 3
0 0 0
1 0 0
1 1 0
0 1 0
0 1 1
1 1 1
1 0 1
0 0 1
R.E Boss
-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens Dan Bron
Verzonden: dinsdag 5 december 2006 16:41
Aan: [email protected]
Onderwerp: [Jprogramming] Gray codes
Given positive integer n , generate the first 2^n Gray codes.
Wikipedia defines Gray codes as a binary numeral system where two
successive values differ in only one digit:
G 3
0 0 0
0 0 1
0 1 1
0 1 0
1 1 0
1 1 1
1 0 1
1 0 0
The format of your result may either be a table of booleans or a list
of integers (which formats can be readily interchanged with #: and
#. ).
#. G 3
0 1 3 2 6 7 5 4
Though the usual metrics of parisimony apply (brief, fast, lean), the
larger goal here is to generate as many __different__ interesting
solutions in J as possible. I chose this problem because I think it's
particularly amenable to that goal. (Though I have to admit that
while I've submitted 5 solutions, they only represent 3 different ways
of attacking the problem; the last two were submitted only out of
pride.)
See http://www.jsoftware.com/jwiki/Puzzles/Gray_Code for the full
rules (and spoilers down the page).
-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm