Here's a challenge, if you make h and I work like f and g will they be
faster?  Note that f is a table, and h is a list.

    f=: 13 :'":,.p:y'
   g=: 13 :'((1=+/"1 (f y)~:'' '')+((1{"1 f y)=2{"1 f y)+(3=+/"1 (f
y)=|:|.|:f y))#f y'
   g i.40
  2
  3
  5
  7
 11
101
131
151
   h=: 13 :'":"0 p:y'
   i=: 13 :'((1=+/"1 (h y)~:'' '')+((1{"1 h y)=2{"1 h y)+(3=+/"1 (h
y)=|:|.|:h y))#h y'
   i i.40
2  
2  
3  
3  
5  
5  
7  
7  
101
131
151

Linda

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Linda A
Alvord
Sent: Sunday, October 18, 2015 10:50 PM
To: [email protected]
Subject: Re: [Jprogramming] Programming Digest, Vol 121, Issue 24

It seems that [: is the problem:

require 'trace'
f=: 13 :'":,.p:y'
f

trace '": ,. p:  i.40'

Try this.  Linda

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of David Lambert
Sent: Sunday, October 18, 2015 2:06 PM
To: programming
Subject: Re: [Jprogramming] Programming Digest, Vol 121, Issue 24

Need also double quote the space?

trace'((1=[:+/"1'' ''~:f)+((1{"1 f)=2{"1 f)+3=[:+/"1 f=[:|:[:|.[:|:f)#f'

This advances us from syntax to index error.


 >Date: Sat, 17 Oct 2015 23:32:34 -0400
 >From: Raul Miller <[email protected]>
 >To: Programming forum <[email protected]>
 >Subject: Re: [Jprogramming] Finding prime palindromes
 >Message-ID:
 > <cad2jou_0ehozf9omcibxujayohfqmo__l9npiyff3s_tbgr...@mail.gmail.com>
 >Content-Type: text/plain; charset=UTF-8  >  >You left out a value for y.
 >
 >Thanks,
 >
 >-- Raul On Sat, Oct 17, 2015 at 9:47 PM, Linda A Alvord
<[email protected]> wrote:
 >> I tried "trace" to see what would happen to g. The results are strange.
 >>
 >> require'trace'
 >>    f=: 13 :'":,.p:y'
 >>    g=: 13 :'((1=+/"1 (f y)~:'' '')+((1{"1 f y)=2{"1 f y)+(3=+/"1 (f
 >> y)=|:|.|:f y))#f y'
 >>    g i.40
 >>   2
 >>   3
 >>   5
 >>   7
 >>  11
 >> 101
 >> 131
 >> 151
 >>    f
 >> [: ": [: ,. p:
 >>    g
 >> ((1 = [: +/"1 ' ' ~: f) + ((1 {"1 f) = 2 {"1 f) + 3 = [: +/"1 f = [: 
|: [:
 >> |. [: |: f) # f
 >>
 >>    trace '[: ": [: ,. p:'
 >>  --------------- 5 Trident ----
 >>  [:
 >>  ,.
 >>  p:
 >>  [: ,. p:
 >>  --------------- 5 Trident ----
 >>  [:
 >>  ":
 >>  [: ,. p:
 >>  [: ": [: ,. p:
 >>  ==============================
 >>
 >>    trace '((1 = [: +/"1 ' ' ~: f) + ((1 {"1 f) = 2 {"1 f) + 3 = [: 
+/"1 f =
 >> [: |: [: |. [: |: f) # f'
 >>  --------------- 3 Adverb -----
 >>  +
 >>  /
 >>  +/
 >>  --------------- 4 Conj -------
 >>  +/
 >>  "
 >>  1
 >>  +/"1
 >>  --------------- 5 Trident ----
 >>  =
 >>  [:
 >>  +/"1
 >>  = [: +/"1
 >>  --------------- 6 Bident -----
 >>  1
 >>  = [: +/"1
 >> |syntax error: executet
 >> |   t_z=.    (1)(=[:+/"1)
 >>
 >> linda
 >>
 >> -----Original Message-----
 >> From: [email protected]
 >> [mailto:[email protected]] On Behalf Of Linda A
>> Alvord  >> Sent: Friday, October 16, 2015 11:31 PM  >> To:
[email protected]  >> Subject: Re: [Jprogramming] Finding prime
palindromes  >>  >> Kip, That was a challenge! Soon someone will do it much
more grcefully!
 >> Simplifications welcome. It is all done in characters.
 >>
 >> f=:[: ": [: ,. p:
 >>
 >> g=:((1 = [: +/"1 ' ' ~: f) + ((1 {"1 f) = 2 {"1 f) + 3 = [: +/"1 f =
[: |:
 >> [: |. [: |: f) # f

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

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

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

Reply via email to