Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #6663

Re: generating permutations

From BartC <bc@freeuk.com>
Newsgroups comp.programming
Subject Re: generating permutations
Date 2016-05-26 13:08 +0100
Organization A noiseless patient Spider
Message-ID <ni6opm$1gt$1@dont-email.me> (permalink)
References (2 earlier) <ad4f7ce6-2699-42e3-815e-3ccce7c0200c@googlegroups.com> <nhuv7g$s2i$1@dont-email.me> <d8c7fea2-8b8d-4cf4-883b-c02b47c49081@googlegroups.com> <ni1fah$3bi$1@dont-email.me> <e2925b6d-a041-4130-84e4-95f88c4b3198@googlegroups.com>

Show all headers | View raw


On 26/05/2016 03:03, luser droog wrote:
> On Tuesday, May 24, 2016 at 6:56:30 AM UTC-5, Bart wrote:
>> On 24/05/2016 05:36, luser droog wrote:
>>> On Monday, May 23, 2016 at 8:09:33 AM UTC-5, Bart wrote:
>>
>>>> For example, take this is 2D array A of 3 rows of 5 columns:
>>>>
>>>>  ((3 1 4 1 5)
>>>>   (9 2 6 5 3)
>>>>   (5 8 9 7 9)
 >>>>   (3 2 3 8 4))  [Reinstated snipped last row)

>> I tried adding this feature on one of my languages, using functions to
>> do the slicing rather than changing the language.
>>
>> It was surprisingly difficult!

> Very cool. It took me an hour to write but a day to
> debug it. Stupid typo early on took forever to find.
>
> Here's a an illustration of some of the slices described upthread,
> adjusting for 0-based indexing.
>
> $ ./olmec
>         b←3 5⍴3 1 4 1 5 9 2 6 5 3 5 8 9 7 9

(Note my example was actually 4x5 but the last row was lost at some point)

>         b[;2 4]
>  4 5
>  6 3
>  9 9

So this is all rows (the first index) and columns 2 and 4.

>         b←4 5⍴3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4
>         b
>  3 1 4 1 5
>  9 2 6 5 3
>  5 8 9 7 9
>  3 2 3 8 4
>
>         b[1]
>  0 0 12 1 3

What does the above do?

>         b[1;]
>  9 2 6 5 3

OK, row 1 of 0..3, and all columns.

>         b[1 2;]
>  9 2 6 5 3
>  5 8 9 7 9
>
>         b[1 2;3]
>  5 7

Select columm 3 of the above two rows, although I would have expected:

    5
    7

>         b[0 2 3;1 3]←'X'
>         b
>  3 X 4 X 5
>  9 2 6 5 3
>  5 X 9 X 9
>  3 X 3 X 4

OK, your assign semantics just treats the rhs as a stream of data or 
whatever shape. When it gets to the end of the data, it starts again.

This a further example you posted to comp.lang.c:

 >         + a←⍳3 3 3
 >   0  1  2
 >   3  4  5
 >   6  7  8
 >
 >   9 10 11
 >  12 13 14
 >  15 16 17
 >
 >  18 19 20
 >  21 22 23
 >  24 25 26
 >
 >
 >         a[2 0;;2]
 >  20 23 26
 >   2  5  8

I had some difficulties with this slicing and had to re-imagine this 
3x3x3 matrix like this in '3D' (fixed pitch font needed):

                             18
                                  19
               9             21        20
                    10            22
0             12        11  24        23
      1             13            25
3          2  15        14            26
      4             16
6          5            17
      7
            8

X index is front to back
Y is top to bottom (omitted, so entire columns are selected)
Z is right to left

So it actually works quite well, apart from the orientation of the 
selection. I'll have a go at implementing this I think, allowing 
repeated indices and using the specified order.

-- 
Bartc

Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

generating permutations luser droog <mijoryx@yahoo.com> - 2016-05-22 02:46 -0700
  Re: generating permutations bart4858@gmail.com - 2016-05-22 05:36 -0700
    Re: generating permutations luser droog <mijoryx@yahoo.com> - 2016-05-22 14:40 -0700
      Re: generating permutations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-05-22 22:58 +0100
      Re: generating permutations BartC <bc@freeuk.com> - 2016-05-23 14:09 +0100
        Re: generating permutations luser droog <mijoryx@yahoo.com> - 2016-05-23 21:36 -0700
          Re: generating permutations BartC <bc@freeuk.com> - 2016-05-24 12:56 +0100
            Re: generating permutations luser droog <mijoryx@yahoo.com> - 2016-05-25 19:03 -0700
              Re: generating permutations BartC <bc@freeuk.com> - 2016-05-26 13:08 +0100
                Re: generating permutations luser droog <mijoryx@yahoo.com> - 2016-05-26 08:35 -0700

csiph-web