Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
A function for calculating and returning maximum ...
Author:
Erdogan Tan
E-mail:
Click to e-mail author
Website:
http://www.singlix.com/download/combinator.html
Submitted:
8/3/2001
Version:
VB3, VB4, V
Compatibility:
VB3, VB4, VB5, VB6, VB.NET
Category:
Mathematics
Views:
13571
A function for calculating and returning maximum possible number of combinations for r elements of n elements (heap). Combination (n as integer, r as integer) as Double Result = n! /((n-r)! * r!) I am using this function for 6/49 lotto automatic column list (with conditions, oblications and prhobitions). n= 49 r=6 (without filtering)
Declarations:
DIM OLASILIK as DOUBLE REM OLASILIK variable will be used as result of REM Combination function for checking automatic list REM limits REM n= number of balls in the bag REM r= number of balls will be used (banko balls REM excluded) REM OLASILIK= Combination(n,r) REM If OLASILIK > LIMIT then
Code:
Private Function Combination(n As Integer, r As Integer) As Double Rem SKORLOTO 417 (Version 2.2) COMBINATOR Version 1.0 , July 2001 Rem http://www.singlix.com/download/combinator.html Rem r=6, n=49 -> LOTTO 6/49 Combinations Rem Banko (Forever) balls and unwanted balls must be excluded Rem before this function (n and/or r may be less then 49 and 6) Rem *** Rem Calculates and returns all of possible combinations Rem with r different elements of total n elements... Rem *** If n < 1 Or r < 1 Then Combination = 0 Rem non-valid input values Else Dim u As Double Dim v As Double Dim w As Integer Dim t As Integer u = 1 For t = 1 To n u = u * t Next t Rem n! is calculated as above v = 1 If n > r Then For t = 1 To n - r v = v * t Next t End If Rem (n-r)! is calculated as above w = 1 For t = 1 To r w = w * t Next t Rem r! is calculated as above Combination = u / (v * w) Rem Combination = n! / ((n-r)! * r!) End If End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement