Another improvement:
initGC=:(<0 1) ,~ 2: <@^ ] ((($~ *)@- +:@{:) , |[EMAIL PROTECTED])
i.@<.&.(2&^.)
GC7=: [:>[:(({. * [EMAIL PROTECTED]) ,@:+ ($ (,: |.)))&.>/ initGC
(GC7 -:GC1) 15
1
100 ts 'GC1 15'
0.0004444057 525312
100 ts 'GC7 15'
0.00021198075 790976
100 ts 'GC1 16'
0.0018220361 1049600
100 ts 'GC7 16'
0.00099963085 1578432
Roughly twice as fast!
R.E. Boss
-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens Dan Bron
Verzonden: donderdag 7 december 2006 15:57
Aan: [email protected]
Onderwerp: RE: [Jprogramming] Gray codes
What a neat solution! Leaner even than the bitwise solution (even
with that 0: , ... on there). Impressive. Please record it on the
wiki.
-Dan
PS: I cannot reproduce your timings:
NB. Work computer
1000 ts 'GC1 15'
0.00137394 525312
1000 ts 'GC3 15'
0.00252186 1.05299e6
1000 ts 'GC6 15'
0.000665091 787264
NB. Home computer
1000 ts 'GC1 15'
0.00102192 525312
1000 ts 'GC3 15'
0.00233702 1.05299e6
1000 ts 'GC6 15'
0.000322889 787264
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm