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


Groups > comp.lang.c > #62044

Re: permutation generator in C

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: permutation generator in C
Date 2015-05-15 16:21 +0100
Organization A noiseless patient Spider
Message-ID <87h9rdlvca.fsf@bsb.me.uk> (permalink)
References <e7aaceef-80c0-429f-8b77-14dc2e514d07@googlegroups.com> <87wq0aku5t.fsf@bsb.me.uk> <8db8265b-d04e-4922-9c8a-a2e5f99a8e42@googlegroups.com>

Show all headers | View raw


asetofsymbols@gmail.com writes:

> Ben wrote:"
> Yes, but it's just a typo.  The line should be 
>
>   exch(N % 2 ? 1 : n, N); 
>
> In previous algorithms the author used c as a counter, so this was a 
> cut-and-paste typo."
>
> Ok it is as above
> but N is fixed (it would be the number
> of element to permute {1..N})
> And there is not a place in the code
> of the not recursive routine that
> change N.
> If N%2==0
> Than the algo can swap only
> 1 and last N in ordered {1..N}
>
> So it can not be right

Yes, I was way too hasty in suggesting the correction.  The iterative
version uses an array of c values (that's why c went from an int to an
array) and the recursive parameter N is replaced with an iterated n.
Thus the original

  exch(N % 2 ? 1 : c, N);

should be

  exch(n % 2 ? 1 : c[n], n);

-- 
Ben.

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


Thread

permutation generator in C asetofsymbols@gmail.com - 2015-05-15 02:19 -0700
  Re: permutation generator in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-15 11:32 +0100
    Re: permutation generator in C asetofsymbols@gmail.com - 2015-05-15 04:44 -0700
      Re: permutation generator in C asetofsymbols@gmail.com - 2015-05-15 04:49 -0700
      Re: permutation generator in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-15 16:21 +0100
        Re: permutation generator in C asetofsymbols@gmail.com - 2015-05-15 11:44 -0700
      Re: permutation generator in C Keith Thompson <kst-u@mib.org> - 2015-05-15 08:26 -0700
  Re: permutation generator in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-15 19:51 +0100
    Re: permutation generator in C asetofsymbols@gmail.com - 2015-05-15 13:38 -0700
      Re: permutation generator in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-15 21:48 +0100
        Re: permutation generator in C asetofsymbols@gmail.com - 2015-05-15 14:05 -0700
          Re: permutation generator in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-15 22:32 +0100
          Re: permutation generator in C Keith Thompson <kst-u@mib.org> - 2015-05-15 14:43 -0700
            Re: permutation generator in C asetofsymbols@gmail.com - 2015-05-15 16:53 -0700
              Re: permutation generator in C Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2015-05-15 18:32 -0600
                Re: permutation generator in C Keith Thompson <kst-u@mib.org> - 2015-05-16 02:03 -0700

csiph-web