On Thu, Mar 21, 2013 at 4:24 PM, David Ward Lambert
<[email protected]> wrote:
> Note 'Lucky spiral'
>  http://en.wikipedia.org/wiki/Lucky_number
>  http://oeis.org/A000959

On Sun, Mar 24, 2013 at 3:55 AM, Aai <[email protected]> wrote:
> split=: {.;}.
> sieve =: [#~#@[$ 0,~<:@]$1:
> lucky=: [:; [:(#@[(>:@[ split ]sieve {),)&>/^:({:&>@{.<#@;)^:_ [: split 1+2*i.

I did not originally pay much attention to this subject.  The concept
of "lucky" initially struck me as "enshrining a buggy attempt at
implementing prime numbers".  Still, with your code here, it's concise
enough of a concept to be fun to work with.

That said, I'd prefer to rearrange things.

Instead of having the right argument to lucky be twice the limit, I'd
prefer to have it just be the limit value.

In other words, instead of:
   >./lucky 1000
1995

I'll implement:
   >./luck 1000
997

[I'm also changing the name, to represent the change in behavior.]

Second, I'd be more comfortable with the list argument to sieve being
its right argument, and the single integer argument being its left
argument. Since this is another behavior change, I'll introduce
another name change:

   3 toss 1+i.7
1 2 4 5 7

toss=:  ] #~ 0 < (| #\)

That gives me toss~ as being equivalent to your sieve. But I'm not
sure whether this rewrite is worth the bother, so I'll just stick with
your sieve.

Meanwhile, your code is really close to being able to use just a
single induction, instead of a double induction.  A little thought
(and experimentation) gives me:

luck=: 0 {:: [: ((] (];0 -.~ >:@#@[ {. ]) (sieve {:))&>/)^:_ 2: ;~ 1 + i.

   luck 20
1 3 7 9 13 15
   #luck 20000
2066
   (luck 20000) -: lucky 10000
1

This allows me a drabble of a pun which borders on being accurately
descriptive: I've halfway doubly eliminated doubling, here.

Anyways, note that I'm taking advantage of J's parser here, in various
ways. Most especially, I'm taking advantage of the fact that verb
words cannot have spaces in their spellings. Only noun words can have
spaces in them. And, 2: is a verb word. I do not need any extra syntax
to convey to the interpreter that _ 2: is two separate words.

Anyways, perhaps some of this is of interest to someone...

Thanks,

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

Reply via email to