Borrowing from https://rosettacode.org/wiki/Permutations#J we could
brute force it by generating all permutations of nine digits, and keep
the unique copies of the first three elements of those (represented as
integers):
perms=: A.&i.~ !
all1=: ~.10#.3{."1]1+perms 9
Faster would be to generate all combinations of digits and then use
all permutations of those combinations
require'stats'
all2=: ,10#.(perms 3){"1/1+3 comb 9
These do not generate the same lists
10{.all1
123 124 125 126 127 128 129 132 134 135
10{.all2
123 124 125 126 127 128 129 134 135 136
but the lists represent equivalent sets
all1 -:&(/:~) all2
1
But, as you've seen in other responses, there's plenty of other approaches.
Thanks,
--
Raul
On Sat, Aug 12, 2017 at 5:16 AM, Skip Cave <[email protected]> wrote:
> 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