Amazing for a quick doodle! Mine are usually wrong and slow.... Mike Please reply to mike_liz....@tiscali.co.uk. Sent from my iPad
> On 12 Aug 2017, at 12:51, 'Jon Hough' via Programming > <programm...@jsoftware.com> wrote: > > Just for fun, let's compare: > > ============================== > My Machine: > Ubuntu 17.x > J 805 > ============================== > NB. Mike's solution > timespacex ' 10#.(#~(3=#@~.)"1) >: 9#.inv i. 9^3' > 0.00127 153216 > > NB. Pascal's solution > perm =: i.@! A. i. > combT =: [: ; ([ ; [: i.@>: -~) ((1 {:: [) ,.&.> [: ,&.>/\. >:&.>@:])^:(0 {:: > [) (<i.1 0) ,~ (<i.0 0) $~ -~ > timespacex '10 #."1 /:~ >: ,/ ({~ perm@#)"1 ] 3 combT 9' > 0.00189 1.1616e6 > > NB. Jon's solution > NB. Note, possibly not fair, since my solution does not give integer results, > but equivalent array representation of each integer > nr=:3&=@:#@:~. *. -.@:(0&e.) > timespacex '(nr"1#])10 10 10#:i.1000' > 0.002559 301568 > > It seems Mike's solution is fast and uses the least amount of memory. > > Interestingly, if I integerify my results: > timespacex ' ". (-.&'' '')@:":"1(nr"1#])10 10 10#:i.1000 ' > 0.001445 522624 > > The speed is faster than just leaving as arrays, even though it uses more > memory (I tried this multiple times, it's always faster). > -------------------------------------------- > On Sat, 8/12/17, 'Pascal Jasmin' via Programming <programm...@jsoftware.com> > wrote: > > Subject: Re: [Jprogramming] Quora problem > To: "programm...@jsoftware.com" <programm...@jsoftware.com> > Date: Saturday, August 12, 2017, 8:33 PM > > a general approach that uses much > longer code, but permutations of combinations, > > perm =: i.@! A. i. > combT =: [: ; ([ ; [: i.@>: -~) ((1 {:: [) > ,.&.> [: ,&.>/\. >:&.>@:])^:(0 {:: > [) (<i.1 0) ,~ (<i.0 0) $~ -~ > > # 10 #."1 /:~ >: ,/ ({~ perm@#)"1 > ] 3 combT 9 > 504 > > > > > > > ________________________________ > From: 'Mike Day' via Programming <programm...@jsoftware.com> > To: programm...@jsoftware.com > > Sent: Saturday, August 12, 2017 7:15 AM > Subject: Re: [Jprogramming] Quora problem > > > > I think Skip wants all permutations, not just > increasing and decreasing > ones, > so here's an alternative: > 5({.,(-@[){.]) > 10#.(#~(3=#@~.)"1) >: 9#.inv i. 9^3 > 123 124 125 126 127 983 984 985 986 987 > > The initial 5 ( ) is of course > just to limit the output! > > Any use? > Mike > > On 12/08/2017 10:56, 'Jon > Hough' via Programming wrote: >> Not > particularly efficient or terse but here: >> >> inc=: > -.@:(0&e.)@:~.@:(2&(</\)) NB. increasing >> dec=: > -.@:(0&e.)@:~.@:(2&(</\)) NB. decreasing >> mt=: inc +. dec NB. monotonic >> >> (-:9*8) }. > (mt"1 # ] ) 10 10 10 #: i. 1000 NB. strip off the first > 9*4 rows. >> > -------------------------------------------- >> On Sat, 8/12/17, Skip Cave <s...@caveconsulting.com> > wrote: >> >> Subject: > [Jprogramming] Quora problem >> To: > "programm...@jsoftware.com" > <programm...@jsoftware.com> >> Date: Saturday, August 12, 2017, 6:16 > PM >> >> How can I > use J to generate all the possible >> > 3-digit integers that can be >> > constructed using the digits 1-9 (no >> > zeros), with no repeated digits in >> > each integer? The sequence starts with >> 123 (smallest) and goes to 987 >> (largest). Here's the first few >> integers in the sequence: >> >> 123 124 125 126 > 127 128 129 132 134 135 >> 136 137 138 > 139 142 143 145 146 147 >> 148 149 152 > 153 154 156 157 158 159 >> 162...... >> >> Skip >> >> Skip Cave >> Cave Consulting LLC >> > ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> > ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm > > > --- > This email has been checked for viruses by > Avast antivirus software. > https://www.avast.com/antivirus > > > ---------------------------------------------------------------------- > 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm