|
||||||
| Pascal/Delphi Forum for discussing Borland Delphi and Pascal coding techniques, tips and tricks. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
hi
can you please help me with this problem? i am trying to generate all combinations of binary number with fix number of digits and number of ones e.g. number of digits=4 and number of ones=2: 0011 0101 0110 1001 1010 1100 have you got any idea how to solve this? thanks a lot |
| Sponsored Links |
|
|
|
|||||
|
Indeed it is, but if you searched on Google using the keywords I said, you would be able to find pages which both covers Delphi and permutations.
If you want information purely about the algorithm itself, then you should check out Wikipedia's article on permutation. |
|
|||||
|
One way to approach it:
Have a for loop from 0 to 2^digits -1. For each value, do a bitwise and against 1,2,4,8,etc, counting the number of results that are 1. Sum the results (to count the number of 1's) and also concatenate the IntToStrings of the results(to build a string to display). If the sum is 2, then print the string.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Programming is a branch of mathematics. |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Guess a Number | 3n! | C and C++ | 2 | 12-02-2007 04:44 PM |
| if text1.text = number | ikkeugh | Visual Basic Programming | 2 | 10-21-2007 11:04 AM |
| Binary, Decimal, Hex, the Manual way!! | TcM | Tutorials | 22 | 01-10-2007 01:06 AM |
| Number Cloning | Ronin | Java Help | 3 | 12-21-2006 08:23 AM |
| Binary Conversion in VB | roger | Visual Basic Programming | 0 | 06-01-2006 11:50 AM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |