First question: The j essays present many algorithms solving the same
problem.  It would be nice if these could be ordered by efficiency.
Granted, the specific j implementation, the problem size, or much else
might affect the result making this request unreasonable.  For instance,
is the structural odometer that a non-mathematician might prefer less
efficient than base representation?

odometer =: #: i.@(*/)         NB. mathematician's version perhaps
odometer2=: [: |: */ $&> */\...@}.@(,&1) #&.> i.&.>   NB. Structural





Second question: What is a more efficient expression?

   NB. characterize the input, b

   $b                NB. b is a vector of 3 million integers
2857143
   *./2(</)\b        NB. b is monotonic.
1
  0 _1{b             NB. from 10 to 150 million
10 149999980

   diff=.2(-~/)\b    NB. successive differences of b

   (+/ % #)diff      NB. mean of differences
52.5
   m28 diff          NB. Standard deviation, from phrases
20.4634
   27+*:0 _1{b       NB. ok without extended precision
127 22499994000000427
   1 p: 1 3 7 9 13 27+"_ 0*:0 _1{b   NB. example, an island of primes?
1 1 1 1 1 1
0 0 0 0 0 0


   b#~(*./"1)1 p: 1 3 7 9 13 27+"_ 0*:b   NB. THE PROBLEM


What is an efficient way to arrange this search for islands of prime
numbers?  In c I wouldn't bother to add 3 and test for primality having
determined that 1+n*n is composite.  *./ should not "short circuit" on
zero as would && in c, since

   *./1 0 _
|NaN error
|       *./1 0 _


Thanks,
Dave.

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

Reply via email to