Wow! I hadn't really realized the power of catalogue '{'. This was a great
learning experience. Thanks to everyone for the posts.

I like keeping these things in the numerical domain:

10#.>,{4#{0 1 2 6

0 1 2 6 10 11 12 16 20 21 22 26 60 61 62 66 100 101 102 106 110 111 112 116
120 121 122 126 160 161 162 166 200 201 202 206 210 211 212 216 220 221 222
226 260 261 262 266 600 601 602 606 610 611 612 616 620 621 622 626 660 661
662 666 1000 1001 1002 1006 ...


However, that is the wrong answer. My original requirement states "using
the characters 0, 1, 2, and 6 once" so duplicate digits are not allowed.


Here's the correct function:


ea =. each.

~.>10#.ea~.ea,{4#{0 1 2 6

0 1 2 6 12 16 21 26 61 62 126 162 216 261 612 621 10 102 106 1026 1062 120
160 1206 1260 1602 1620 20 201 206 2016 2061 210 2106 2160 260 2601 2610 60
601 602 6012 6021 610 6102 6120 620 6201 6210

Is there any way to get rid of the extra 'eaches' in the function? Or is
that the route I must take to use integers instead of characters?

In any case, using catalogue is much nicer than my original function:


load 'stats'

~.>10#.ea({1{."1 a),({2{."1 a),({3{."1 a),{a=.(perm 4){0 1 2 6

0 1 2 6 10 12 16 20 21 26 60 61 62 102 106 120 126 160 162 201 206 210 216
260 261 601 602 610 612 620 621 1026 1062 1206 1260 1602 1620 2016 2061
2106 2160 2601 2610 6012 6021 6102 6120 6201 6210


Cliff showed a nice, concise way to perform the function using characters:

~.,".@:~.&>{4#<'0126'

0 1 2 6 12 16 21 26 61 62 126 162 216 261 612 621 10 102 106 1026 1062 120
160 1206 1260 1602 1620 20 201 206 2016 2061 210 2106 2160 260 2601 2610 60
601 602 6012 6021 610 6102 6120 620 6201 6210

I haven't been able to move that approach to the number domain:

~.,10#.~.,@:~.&>{4#<0 1 2 6

0 100 200 600 120 160 210 260 610 620 126 162 216 261 612 621 1000 1020
1060 1026 1062 1200 1600 1260 1620 1206 1602 2000 2010 2060 2016 2061 2100
2106 2160 2600 2610 2601 6000 6010 6020 6012 6021 6100 6102 6120 6200 6201
6210

(Wrong)


Skip

Skip Cave
Cave Consulting LLC


On Mon, Oct 21, 2019 at 10:16 AM Raul Miller <[email protected]> wrote:

> I think maybe that first one should have been
>
>    ".>,{4#<'0126'
> 0 1 2 6 10 11 12 16 20 21 22 26 60 61 62 66 100 101 102 106 110 111
> 112 116 120 121 122 126 160 161 162 166 200 201 202 206 210 211 212
> 216 220 221 222 226 260 261 262 266 600 601 602 606 610 611 612 616
> 620 621 622 626 660 661 662 666 1000 1001 1002 1006 ...
>
> Thanks,
>
> --
> Raul
>
> On Mon, Oct 21, 2019 at 8:54 AM Clifford Reiter <[email protected]>
> wrote:
> >
> > Using Cartesian with duplicate digits
> >
> >  ,".@:~.&>{4#<'0126'
> >
> > 0 1 2 6 1 1 12 16 2 21 2 26 6 61 62 6 1 1 12 16 1 1 12 16 12 12 12 126 16
> > 16 162 16 2 21 2 26 21 21 21 216 2 21 2 26 26 261 26 26 6 61 62 6 61 61
> 612
> > 61 62 621 62 62 6 61 62 6 10 10 102 106 10 10 102 106 102 102 102 1026
> 106
> > 106 1062 106 10 10 102 106 10 1...
> >
> >
> > Without duplicates
> >
> > ~.,".@:~.&>{4#<'0126'
> >
> > 0 1 2 6 12 16 21 26 61 62 126 162 216 261 612 621 10 102 106 1026 1062
> 120
> > 160 1206 1260 1602 1620 20 201 206 2016 2061 210 2106 2160 260 2601 2610
> 60
> > 601 602 6012 6021 610 6102 6120 620 6201 6210
> > ----------------------------------------------------------------------
> > 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