[Jprogramming] how to arrange ( ( (A f 2) f 3 ) f 4) f 5 ... all the way to 27?

Raul Miller rauldmiller at gmail.com
Wed May 23 05:05:11 HKT 2007


On 5/22/07, Terrence Brannon <metaperl.j at gmail.com> wrote:
> Raul Miller <rauldmiller <at> gmail.com> writes:
> > You mean like this?
> >    A ( [: > process_prime~&.>/ <"0 @ |. @ ] , < @ [) 2}.i.28
>
> Once again, you have completely out-classed me. I will need to do
> some serious head-scratching before I understand what you are doing.

Well... first off, I goofed.  I didn't test the code (I did this
without definitions
for A and process_prime).  I think this should work though:

   A ([: > [: process_prime~&.>/ <"0@|.@] , <@[) 2}.i.28

Second off, if something is confusing, looking at the data usually helps.
For example, cutting the inner train, two verbs at a time, until I get rid
of process_prime:

      A ( [: process_prime~&.>/ <"0@|.@] , <@[) 2}.i.28
      A (<"0@|.@] , <@[) 2}.i.28

And, substituting an arbitrary value for A:
      'A' (<"0@|.@] , <@[) 2}.i.28

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-+-+-+-+-+-+-+-+-+
|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|A|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-+-+-+-+-+-+-+-+-+

Basically, I've put each of the arguments in boxes, and arranged them
so a right-to-left scan will process them in the right order.  Note also
that I'm using
   process_prime~&.>/

Here's how those adverbs kick in:
   /   process the data in from right to left, using the dyad:
  &.> which works inside the boxes with the dyad:
  ~   swapping left and right arguments with the dyad: process_prime

Once that's all done, my result is in a box,  I have to unbox it for the
final result.

I hope this helps (and I hope I did not make any other mistakes).

> here is the algorithm - http://www.nist.gov/dads/HTML/sieve.html

With that specification, I'd be tempted to implement it as:

sieve=:3 :0
  r=.(y+1){.1 1
  for_prime.i.&.(p:inv)y do.
    r=.1 ((prime*}.>:i.y<.@%prime))} r
  end.
  r
)

Or, tacitly, ... nah, I don't want to overwhelm you (but the basic technique
is the same one I illustrated above -- using &.>/

Of course, I'm being a bit silly, but I guess that's because I feel the
concept is a bit silly.

-- 
Raul


More information about the Programming mailing list