For this, I think I would have gone with: selPrime=: #~ 1&p: seed=: selPrime digits=: 1+i.9 step=: selPrime@,@:(,&.(10x&#.inv)/&>)@{@; digits&step&.>^:a: ,<seed
Which, granted, is not particularly fast. (That last line takes about 15 seconds on my current laptop.) Not sure if this helps, though... -- Raul On Sun, Nov 20, 2022 at 8:37 PM 'Pascal Jasmin' via Programming <programm...@jsoftware.com> wrote: > > based on Raul's rosettacode link, but building an expaning list of left > truncable primes, such that further search is possible on future "iterations" > > > selPrime=: #~ 1&p: > > ltrunc =: (] , ((1+i.9) (10 #. ,)"0 1 (10&#.inv))"0(,@:)(selPrime@:) each@:{:) > > # &> sofar =: ltrunc^:6 < 3 7x > > 2 11 39 99 192 326 429 > > # &> sofar =: ltrunc^:6 sofar > > 2 11 39 99 192 326 429 521 545 517 448 354 276 > > the number of truncable primes decreases substantially as the digits > increase. (last answer is for 1 to 13 digits, with single digit primes > wrongly listed (4 is right number of single digit primes) > > the full list eventually goes to 0 > > # &> sofar =: ltrunc^:1 sofar (NB. iterations skipped) > > 2 11 39 99 192 326 429 521 545 517 448 354 276 212 117 72 42 24 13 6 5 4 3 1 0 > > which I guess we knew from example number > > > _2 { sofar > > 357686312646216567629137 > > > On Saturday, November 19, 2022 at 07:04:25 p.m. EST, Raul Miller > <rauldmil...@gmail.com> wrote: > > > > > > On Sat, Nov 19, 2022 at 6:47 PM 'Skip Cave' via Programming > <programm...@jsoftware.com> wrote: > > Now what is the J verb that will find an n-digit integer that is still > > prime when each of the digits are removed? > > I'd probably go with https://rosettacode.org/wiki/Truncatable_primes#J for > that. > > Thanks, > > -- > Raul > > ---------------------------------------------------------------------- > 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