Note 'Lucky spiral'
 http://en.wikipedia.org/wiki/Lucky_number
 http://oeis.org/A000959

 Seeing  that  lucky  numbers  have great  commonality  with
 primes, I found that the lucky correspondent to Ulam spiral
 shares diagonal lines.
)

lucky =: 3 : 0 NB. make lucky numbers from 1 to doubled y
 A =. >: +: i. y
 N =. 1
 M =. 1
 while. M (< #) A do.
  M =. N { A
  A =. ((#A) $ -. (-M) {. 1) # A
  N =. >: N
 end.
 A
)
assert 1 3 7 9 13 15 21 25 -: lucky 13

cw=:|:@:|. NB. clockwise matrix rotation
assert (> 3 0 ; 4 1 ; 5 2) -: cw i. 2 3
 
spiral =: (, (>:@:(*/) + i.@:}.)@:$)@:cw
assert (> 5 4 3 ; 6 1 2 ; 7 8 9) -: (spiral^:4)1 1$1

L =: lucky 10000
S =: (spiral^:284) 1 1 $ 1

LS =: S e. L
ULAM =: 1 p: S

load'viewmat'
viewmat LS
NB. viewmat ULAM
NB. viewmat ULAM++:LS


NB. ps. lucky might be a good candidate as example
NB.     for conversion to tacit form.


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to