comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Permutation generator in ada library
Date: Fri, 03 Oct 2014 09:28:35 +0300
Date: 2014-10-03T09:28:35+03:00	[thread overview]
Message-ID: <c96u0hFp4seU1@mid.individual.net> (raw)
In-Reply-To: <983aef70-7b6a-45dc-a7ac-a92874ff66de@googlegroups.com>

On 14-10-03 07:51 , Stribor40 wrote:
> Is there Ada library for this .....
> 
> Code from that link gives wrong output...lets say for 3 gives..
> 
>  1 2 3
>  1 3 2
>  2 1 3
>  2 3 1
>  3 1 2
>  3 2 1
>  3 2 1 <- this shouldnt be there??

Right. The author of this program has confused herself with the
"Is_Last" output parameters of the procedures, and has not documented
them properly. They work differently for the two procedures:

- Generic_Perm.Set_First returns Is_Last = True when the permutation it
PRODUCES is the last one (that is, when N = 1).

- Generic_Perm.Go_To_Next returns Is_Last = True when the permutation it
is GIVEN is the last one, and it does not produce a new permutation in
that case.

The loop in Print_Perms consequently should have a more complex form,
for example like this:

      Perms.Set_To_First(P, Done);
      Print (P);
      if not Done then
         -- There is more than one permutation, print them:
         loop
            Perms.Go_To_Next(P, Done);
            exit when Done;
            -- There was a next permutation, print it:
            Print(P);
         end loop;
      end if;

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .

  reply	other threads:[~2014-10-03  6:28 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-03  0:36 Permutation generator in ada library Stribor40
2014-10-03  4:01 ` Stribor40
2014-10-03  4:34   ` AdaMagica
2014-10-03  4:47     ` Stribor40
2014-10-03 19:32       ` Shark8
2014-10-03 20:47         ` Simon Wright
2014-10-04  3:01           ` Shark8
2014-10-04  7:05             ` Simon Wright
2014-10-09 22:29           ` Randy Brukardt
2014-10-03  4:51     ` Stribor40
2014-10-03  6:28       ` Niklas Holsti [this message]
2014-10-03 10:10         ` Stribor40
2014-10-03 11:13           ` Simon Wright
2014-10-03  4:36   ` Niklas Holsti
2014-10-03  4:42     ` Stribor40
2014-10-03 11:00   ` Brian Drummond
2014-10-03 16:08     ` Niklas Holsti
2014-10-03 16:57       ` Björn Lundin
2014-10-03 12:54 ` john
2014-10-03 18:50 ` jpwoodruff
2014-10-04 18:06   ` Dirk Craeynest
2014-10-09 22:37     ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox