Mebbe I am missing the pint heah:
Instead of
(((A pp 2) pp 3) pp4)...
what if you stated it as
4 pp 3 pp 2 pp A
as a slightly more friendly way of looking at it?
After all, you can always rewrite process_prime that way, or
...provide a wrapper
And that in turn should make the code a bit cleaner:
i) generate your list (2 3 4 ...)
ii) reverse it (4 3 2)
iii) scan apply it to A.
Now: restate that recursively in lazy evaluative form ...
because: ...
On 5/22/07, Terrence Brannon <[EMAIL PROTECTED]> wrote:
Raul Miller <rauldmiller <at> gmail.com> writes:
>
> On 5/22/07, Terrence Brannon <metaperl.j <at> gmail.com> wrote:
> > Concretely, so you can play with things, I need to call
> >
> > (((A process_prime 2) process_prime 3) process_prime 4) ...
process_prime 27
>
> You mean like this?
> A ( [: > process_prime~&.>/ <"0 @ |. @ ] , < @ [) 2}.i.28
after i.28, the rest of it seems like a hole lotta syntax for what should
be
reverse, append, scan/reduce....
Cheers.
Once again, you have completely out-classed me. I will need to do some
serious
head-scratching before I understand what you are doing.
>
> (I've not studied the rest of your code. And, for that matter, I don't
> really understand your goals for that code.)
>
My goals are to perform a naive implementation of the Sieve of
Eratosthenes.
Naive in 2 senses: (1) me the naive novice newbie J'er (2) non-optimal so
as to
satisfy the Benchmark Gods of Alioth :)
here is the algorithm - http://www.nist.gov/dads/HTML/sieve.html
And I am at the step where I consider 2 prime but mark all of its
multiples as
non-prime, then take that marked array and consider 3 prime but mark all
of its
multiples as non-prime, then take that marked array and consider 5 prime
but
mark all of its multiples as non-prime.
code follows -
multiples =: 4 : 'y * (1 + ( i.(>. x % y)))' NB. max multiples n
make_sieve =: 3 : '0 (0 1) } (y+1) $ 1'
next_prime =: prime_indices pick_prime ]
prime_indices =: I. @ [ NB. return indices in list which equal 1
pick_prime =: I. { [ NB. dyadic fork to lookup the
drop_le =: 4 : '(x > y) # x' NB. drop elements in list <= value
NB. A process_prime 2 - marks all multiples of 2 in A as non-prime
process_prime =: 4 : '0 (}: }. (((#x)-1) multiples y)) } x'
A =: make_sieve 27
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
--
--
Roy A. Crabtree
UNC '76 gaa.lifer#
(For TN contact, email me to set up a confirmed date/time)
[When you hear/read/see/feel what a yehudi plays/writes/sculpts/holds]
[(n)either violinist {Menuhin} (n)or writer {"The Yehudi Principle"} (n)or
molder (n)or older]
[you must strive/think/look/sense all of it, or you will miss the meanings
of it all]
[EMAIL PROTECTED] Forwards only to:
[EMAIL PROTECTED] CC: auto to:
[EMAIL PROTECTED] Be short < 160 chars cuts off; currently
offline
[EMAIL PROTECTED] CC: auto to ^
http://www.authorsden.com/royacrabtree
http://skyscraper.fortunecity.com/activex/720/resume/full.doc
--
(c) RAC/IP, ARE,PRO,PAST
(Copyright) Roy Andrew Crabtree/In Perpetuity
All Rights/Reserved Explicitly
Public Reuse Only
Profits Always Safe Traded
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm