Subject: RE: [hackers-il] Another Interesting Case Study: Permutations of a range of characters

From: Omer Musaev <[email-masked]>
Date: Wed, 16 Jan 2002 11:28:16 +0200

Well, no one had created a C++ version.
So here it is:

Standard disclaimers apply.

C++
-----------
#include <string>
#include <algorithm>
using namespace std ;
int 
main ( int argc, char* argv[] )
{
   string current_permutation( "1234" ) ;
   do 
   {
      cout << current_permutation << endl ;
   } while ( next_permutation ( current_permutation.begin (),
                                current_permutation.end () ) ) ;
}
-------------

---

From: Shlomi Fish <[email-masked]>
Date: Wed, 16 Jan 2002 12:47:23 +0200 (IST)

> Standard disclaimers apply.

Unfortunately, this program does not do what the other programs do. It is
possible for a permutation that contains more than one identical
character. The order is "aaa", "aab", etc.

BTW, the bash script, which I wrote just now very quickly is:

#!/bin/bash
A={a,b,c,d,e}
PERM="$A$A$A"
echo "for I in $PERM ; do echo \$I ; done" | bash

(sorry - no sh for you. I need the {a,b,c} construct)

Regards,

	Shlomi Fish

>
>
> To unsubscribe from this group, send an email to:
> [email-masked]
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>

----------------------------------------------------------------------
Shlomi Fish        [email-masked]
Home Page:         http://t2.technion.ac.il/~shlomif/
Home E-mail:       [email-masked]

"Let's suppose you have a table with 2^n cups..."
"Wait a second - is n a natural number?"

---

From: Oleg Goldshmidt <[email-masked]>
Date: 16 Jan 2002 16:57:56 +0200

> Standard disclaimers apply.

Very nice, of course, but it is a bit off the target, IMHO: the point
was to write the algorithm in different languages, and not demonstrate
the power of available (even if standard) libraries. 

I don't know if the actual code implementing permutation algorithms is 
very elegant, but the result scores a point to generic programming, no
doubt.

-- 
Oleg Goldshmidt | [email-masked] 
"If it ain't broken, it has not got enough features yet."