GC1=: [: +/\ 0: , (, (>:@# , -@|.))^:(]`([EMAIL PROTECTED]:)) GC1 3 0 1 3 2 6 7 5 4
(GC1-:,@(, ,:;.0 + */@:$)^:(]`0:))15 1 100 ts 'GC1 15' 0.00044229987 525312 100 ts'(, ,:;.0 + */@:$)^:(]`0:)15' NB. number 3 0.0018677993 1055680 100 ts'(22 b. _1: 33 b. ])@:(2 i.@:^ ])15' NB. number 6 0.00029754291 788736 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
