Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


code to write out combinations e.g. (10 choose 3)


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-03-2008, 01:11 PM
Senior Member
 
Join Date: Apr 2007
Posts: 192
Default code to write out combinations e.g. (10 choose 3)

Hi,

Related to my last question is the following. Does anyone have code to write out every possible combination (not permutation) from a given number X taken out Y (X choose Y)?
Any help appreciated. i just cannot seem to get the appropriate number written out.
Thx
Marc
Reply With Quote
  #2 (permalink)  
Old 02-03-2008, 01:50 PM
Senior Member
 
Join Date: May 2007
Posts: 152
Awards Showcase
Competition Winner 
Total Awards: 1
Default combination

Try this link
http://en.wikipedia.org/wiki/Mathematical_combination

as an example - to choose 3 out of 10 you have :

10! / (3! * (10-3)!) = 3628800/(6*5040) = 120

(calculated by SCalculator , since the only code you need is Factorial function, you can find it there.)
__________________
David Erez
Ramat Hasharon, Israel
Reply With Quote
  #3 (permalink)  
Old 02-03-2008, 02:01 PM
Senior Member
 
Join Date: May 2007
Posts: 152
Awards Showcase
Competition Winner 
Total Awards: 1
Default combination

Here is conceptual code, not debugged:
sub combination(x,y)
a = 1
for i = 1 to x
a = a*i
next
b = 1
for i = 1 to y
b=b*i
next
c=1
for i = 1 to x-y
c= c*i
next
return a/(b*c)
end sub
__________________
David Erez
Ramat Hasharon, Israel
Reply With Quote
  #4 (permalink)  
Old 02-03-2008, 02:42 PM
Senior Member
 
Join Date: Apr 2007
Posts: 192
Default

thnx guys, but I need the code for writing out the different combinations.
Reply With Quote
  #5 (permalink)  
Old 02-04-2008, 05:51 AM
Senior Member
 
Join Date: May 2007
Posts: 152
Awards Showcase
Competition Winner 
Total Awards: 1
Default

Okay, I took the challenge !
see the attached program, both displaying and storing in a file.
fill the a out of b and press go. you will get the number of combinations and the last one, and you can brouse up and down.
Attached Files
File Type: zip combinations.zip (849 Bytes, 7 views)
__________________
David Erez
Ramat Hasharon, Israel

Last edited by derez : 02-04-2008 at 06:27 AM.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

vB 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
Write IF error GallyHC Questions & Help Needed 4 06-02-2008 05:42 PM
Choose Folder - Optimized Compilation orhan Questions & Help Needed 9 05-15-2008 02:36 PM
Combinations Sub: choose(n,k) Stellaferox Code Samples & Tips 2 02-21-2008 06:51 PM
Combinations function derez Share Your Creations 0 02-04-2008 11:40 AM
Tip on how not to write speedy code kolbe Code Samples & Tips 1 01-30-2008 08:20 AM


All times are GMT. The time now is 07:41 AM.


Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0