Lost Password?

Go Back   CodeCall Programming Forum > Software Development > Pascal/Delphi

Pascal/Delphi Forum for discussing Borland Delphi and Pascal coding techniques, tips and tricks.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-26-2008, 02:19 AM
gor gor is offline
Newbie
 
Join Date: Sep 2007
Posts: 4
Rep Power: 0
gor is on a distinguished road
Default binary number combination

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 02-26-2008, 05:16 AM
v0id's Avatar   
v0id v0id is offline
Super Mod
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,007
Last Blog:
CherryPy(thon)
Rep Power: 21
v0id is just really nicev0id is just really nicev0id is just really nicev0id is just really nice
Send a message via MSN to v0id
Default

What language do you want to do this in? This is both a Python and Delphi forum. Kinda odd, now when I'm thinking of it. Maybe Jordan could change it?

Use your favorite search engine for searching on:
"Python permutations"
or, if you're using Delphi:
"Delphi permutations"
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Finally we got that Python-forum!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-26-2008, 05:23 AM
gor gor is offline
Newbie
 
Join Date: Sep 2007
Posts: 4
Rep Power: 0
gor is on a distinguished road
Default

Quote:
Originally Posted by v0id View Post
What language do you want to do this in?
delphi

but this is more question about algorithms
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-26-2008, 06:49 AM
v0id's Avatar   
v0id v0id is offline
Super Mod
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,007
Last Blog:
CherryPy(thon)
Rep Power: 21
v0id is just really nicev0id is just really nicev0id is just really nicev0id is just really nice
Send a message via MSN to v0id
Default

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.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Finally we got that Python-forum!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-26-2008, 11:24 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Mod
 
Join Date: Jul 2006
Age: 35
Posts: 1,857
Last Blog:
Game software (GURPS)
Rep Power: 21
WingedPanther has a spectacular aura aboutWingedPanther has a spectacular aura about
Default

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
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Guess a Number 3n! C and C++ 2 12-02-2007 03:44 PM
if text1.text = number ikkeugh Visual Basic Programming 2 10-21-2007 10:04 AM
Binary, Decimal, Hex, the Manual way!! TcM Tutorials, Classes and Code 22 01-10-2007 12:06 AM
Number Cloning Ronin Java Help 3 12-21-2006 07:23 AM
Binary Conversion in VB roger Visual Basic Programming 0 06-01-2006 10:50 AM


All times are GMT -5. The time now is 07:35 PM.

Contest Stats

Xav ........ 164.00000
dargueta ........ 128.00000
John ........ 127.00000
gaylo565 ........ 18.00000
XaNaX ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

Ads