Advertisement

09.14.2005 at 04:55PM PDT, ID: 21561958
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

How to list all possible number combinations from some given single digit numbers

Tags: combinations, number, possible, all

Hi,

Trying to get my head around how to generate all possible number combinations from only four unique numbers. For example: 2, 1, 8, 3 in all possible combinations: 1238, 2138, 3812 and so on.

What is the best way to go about doing this?

Thanks

 
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: Elastex
Solution Provided By: slyong
Participating Experts: 4
Solution Grade: A
Views: 208
Translate:
Loading Advertisement...
09.14.2005 at 05:22PM PDT, ID: 14885955

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2005 at 05:54PM PDT, ID: 14886073

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2005 at 11:25PM PDT, ID: 14887081

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.15.2005 at 09:36AM PDT, ID: 14890880

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.15.2005 at 10:52AM PDT, ID: 14891566

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.15.2005 at 12:23PM PDT, ID: 14892495

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.16.2005 at 11:50AM PDT, ID: 14900456

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
09.14.2005 at 05:22PM PDT, ID: 14885955

Rank: Wizard

Is this homework?
One way would be to use three nested loops to rearrange an array
 
09.14.2005 at 05:54PM PDT, ID: 14886073
There are quite a few permutation algorithm out there...:

1 - Recursive permutation algorithm like ozo said
2 - A permutation algorithm based on a string permutation algorithm
3 - An ordered (lexicographic) permuation algorithm

Google up "number permutation algorithm c" will land you into those pages.
Accepted Solution
 
09.14.2005 at 11:25PM PDT, ID: 14887081
The simplest algorithm would be to treat each number as a symbol and assign it a numeric value: 0, 1, 2, 3.  Each symbol will have two bits. 4 symbols is 8 bits or one unsigned char.

Therefore - all possible permutations are represented by all the values of unsigned char, i.e. 0-255. To see what the symbols are represented, split the unsigned char into 4 2bit ints and use that as an index into your symbol table.

The only remaining trick is to filter out every instance where a symbol is shown multiple times. All that is left is the desired result.

Your algorithm will have a for(;;) loop and a one line filter. It would be cool if you could post your results here.

Bill
 
09.15.2005 at 09:36AM PDT, ID: 14890880
Preferable to use recursion. It will print all permutations. Pseudocode given below:

permute(string1, string2)
{
if length(string2) = 1 then
  print string1 + string2
else
  for i = 1 to length(string2)
     string3 = string1 + first_character_of(string2)
     string4 = 2nd character of string2 to end of string
     permute(string3, string4)
     rotate string 2 left by 1 character, and put the original 1st character to end of string
   next
endif
return
}

main()
{
permute("", string)
}
 
09.15.2005 at 10:52AM PDT, ID: 14891566


Thanks slyong.

That's what I needed to know: permutation algorithm.


ozo
No it is not homework, just trying to learn how to program in C...

Bill
Below is code that does what I want...

#include <stdio.h>

void out(const int *s, const int size)
{
  if (s != 0) {
    for (int i = 0; i < size; i++) {
      printf("%1d", s[i] );
    }
    printf("\n");
  }
}


void permute(int *s, const int start, const int n)
{  
  if (start == n-1) {
    out(s, n);
  }
  else {
    for (int i = start; i < n; i++) {
      int tmp = s[i];
     
      s[i] = s[start];
      s[start] = tmp;
      permute(s, start+1, n);
      s[start] = s[i];
      s[i] = tmp;
    }
  }
}

main()
{
  int s[] = {1, 2, 3, 8};
  permute(s, 0, sizeof(s)/sizeof(int));
}
 
09.15.2005 at 12:23PM PDT, ID: 14892495
In computer science classes, understanding recursion is extremely important and a great achievement. Being able to find a recursive solution for a problem is something that only those with a real understanding of software engineering can do.

Given that, and having been writing embedded software for umpteen years (where recursion is not allowed because of its unbounded nature), I discovered that it is even more elegant to take the recursive solution and create a non-recursive solution. When that is done. you will find that ultimately, the final solution will be even more efficient.

Take the following code snippit:
 
char S[4] = "2183";
for (i=0; i<256; i++) {
   if ( /* filter code not included in case this is homework */ )
      print ( "%c, %c, %c, %c\n", S[i&0x03], S[(i>>2)&0x03], ...etc... );
}

For the filter code, think of using the parts of i as an index into a boolean array placed in a for(;;) loop.

As you can see, the elegance of simplicity outweighs the elegance of recursion. (IMHO)

Once the solution is posted, I will post the filter code. It is as simple as the above snippit.

Keep on coding!
Bill
 
09.16.2005 at 11:50AM PDT, ID: 14900456
A shorter one pass solution...

=====================================
#include <stdio.h>

char S[4] = "2183";

main()
{
        int i,j;
        int b[4] = {0,0,0,0};

        for ( i=0; i<256; i++) {
                b[0]=b[1]=b[2]=b[3]=0;                     // zero the flags
                for ( j=0; j<4; j++ ) {                    // Filter
                        if ( b[(i>>(j*2))&0x03] ) break;   // test if the flag indexed by 2 bit value is set
                        b[(i>>(j*2))&0x03] = 1;            // Was not set - so set it
                }
                if ( j==4 )      // this means we went thru all 4 iterations with no dulplicates
                        printf( "%c, %c, %c, %c\n",
                                S[(i)&0x03], S[(i>>2)&0x03], S[(i>>4)&0x03], S[(i>>6)&0x03] );
        }
}
 
 
20080236-EE-VQP-29