If you look at the first 10 values from +/"1 map*pan I think you will see duplicates: +/"1 (10#,:i.-9)*((i.10) A. ]) i.9 84 85 85 87 87 88 85 86 87 90
Is that what you really want? -- Raul On Fri, Jul 8, 2011 at 10:08 AM, David Vaughan <[email protected]> wrote: > I have made a list called map: > map=:362880 9 $ \:~10^i.9 > And pan represents all the permutations of 1-9. > So what is wrong with this: > (#~ 1&p:)+/"1 map*pan > ? > > > ___________________________ > > David Vaughan > > On 8 Jul 2011, at 14:13, Roger Hui <[email protected]> wrote: > >> As Dan Bron indicated, if you are looking for pandigital >> primes it's best to avoid generating all permutations. >> Many of the permutations (e.g. ones where the last digit >> is even) are not prime; generating them only to reject them >> represents a large wasted effort. >> >> >> >> ----- Original Message ----- >> From: David Vaughan <[email protected]> >> Date: Friday, July 8, 2011 6:03 >> Subject: Re: [Jprogramming] Checking permutations >> To: Programming forum <[email protected]> >> >>> Yeah, it is for PE - ive done the other pandigital problems in >>> C, but i wanted to try this one in J. >>> My biggest problem seems to be trying to flatten the >>> pandigitals. E.g. >>> >>> 9 8 7 6 5 4 3 2 1 >>> >>> I need to turn into 987654321. Is it possible to do that or do I >>> need to do >>> 1+2*10+3*100+...+9*100000000? >>> >>> ___________________________ >>> >>> David Vaughan >>> >>> On 8 Jul 2011, at 12:38, Ric Sherlock <[email protected]> wrote: >>> >>>> Project Euler? >>>> >>>> To get the permutations in reverse order you could reverse the >>> string> or reverse the list of permutation indicies. i.e. >>>> 0 1 2 3 A. 'cba' >>>> 3 2 1 0 A. 'abc' >>>> >>>> In J you are better off testing the whole array of >>> permutations rather >>>> than looping through them, so >>>> (1&p: # ]) i. 50 >>>> or >>>> (#~ 1&p:) i. 50 >>>> 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 >>>> >>>> On Fri, Jul 8, 2011 at 10:53 PM, David Vaughan >>>> <[email protected]> wrote: >>>>> I'm trying to find the highest 1-9 pandigital prime, so I >>> need to get the permutations in reverse order if possible. Also, >>> how can I apply my primeTest script to the results? >>>>> >>>>> primeTest =: 3 : 'if. #@:q:y do. y end. ' >>>>> This is what I have so far. The rank of y and of the list of >>> permutations don't match up, and it feels like my 'if.' approach >>> isnt great. >>>>> >>>>> Can anyone offer any advice as to how achieve this? >>>>> >>>>> Thanks. >>>>> >>>>> ___________________________ >>>>> >>>>> David Vaughan >>>>> >>>>> On 8 Jul 2011, at 11:29, Ric Sherlock <[email protected]> wrote: >>>>> >>>>>> (i.@!@# A. ]) 'abcd' >>>>>> or >>>>>> (A.~ i.@!@#) 'abcd' >>>>>> >>>>>> see also: >>>>>> http://rosettacode.org/wiki/Find_the_missing_permutation#J >>>>>> >>>>>> On Fri, Jul 8, 2011 at 9:44 PM, David Vaughan >>>>>> <[email protected]> wrote: >>>>>>> >>>>>>> How would you go about getting all the permutations of a >>> string in J? >> >> ---------------------------------------------------------------------- >> 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
