TooManySecrets Posted December 31, 2008 Share Posted December 31, 2008 (edited) okay I need a division algorithim(i'm only in pre-algrebra so i cant think of my own) lets say i have 2 cups and 5 balls i need the number of possible divisions EG: ----- |1|4| ----- |2|3| ----- |3|2| ----- |4|1| ----- |5|0| ----- |0|5| ----- 6 possibilities i need to do this in x number of cups and y number of balls. please help edit: I just need thr possibilities Edited December 31, 2008 by TooManySecrets Link to comment Share on other sites More sharing options...
igotandrew Posted December 31, 2008 Share Posted December 31, 2008 (edited) Aren't those ways to add up to 5? Solve(15) Func Solve($Ball = 0) Local $i = 0, $aCount = 0 For $i = 1 to $Ball MsgBox(0, 0, "Cup 1: " & $i & " || Cup 2: " & $Ball - $i) Next EndFunc I'm still thinking on how to implement the # of cups into this. Edited December 31, 2008 by igotandrew Link to comment Share on other sites More sharing options...
TooManySecrets Posted December 31, 2008 Author Share Posted December 31, 2008 Aren't those ways to add up to 5? Solve(15) Func Solve($Ball = 0) Local $i = 0, $aCount = 0 For $i = 1 to $Ball MsgBox(0, 0, "Cup 1: " & $i & " || Cup 2: " & $Ball - $i) Next EndFunc I'm still thinking on how to implement the # of cups into this.i dont understand your code? it not cup 1 and cup 2 it's 1 cup 2 cups. you get it ? Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 31, 2008 Share Posted December 31, 2008 This makes a good exercise in recursion: expandcollapse popupGlobal $sCups, $iCups, $sBalls, $iBalls, $sResults = "" ; Get number of cups $sCups = InputBox("Cups", "Enter number of cups: ") If @error Then Exit Else $iCups = Int($sCups) If $iCups < 1 Then Exit EndIf ; Get number of balls $sBalls = InputBox("Balls", "Enter number of balls: ") If @error Then Exit Else $iBalls = Int($sBalls) If $iBalls < 1 Then Exit EndIf ; Get recursive results _AddResults($iCups, $iBalls, "") MsgBox(64, "Results", $sResults) ; ---------------------------------------- ; Function _AddResults() ; Recursively adds possible combinations of balls in cups ; $iC = no. of cups remaining ; $iB = no. of balls remaining ; $sLine = current string being assembled ; ---------------------------------------- Func _AddResults($iC, $iB, $sLine) $sLine &= "|" If $iC = 1 Then ; Last cup, end of line $sResults &= $sLine & $iB & "|" & @CRLF Else ; Not the last cup, recurse For $b = $iB To 0 Step -1 _AddResults($iC - 1, $iB - $b, $sLine & $b) Next EndIf EndFunc Happy New Year! Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
TooManySecrets Posted December 31, 2008 Author Share Posted December 31, 2008 (edited) This makes a good exercise in recursion: expandcollapse popupGlobal $sCups, $iCups, $sBalls, $iBalls, $sResults = "" ; Get number of cups $sCups = InputBox("Cups", "Enter number of cups: ") If @error Then Exit Else $iCups = Int($sCups) If $iCups < 1 Then Exit EndIf ; Get number of balls $sBalls = InputBox("Balls", "Enter number of balls: ") If @error Then Exit Else $iBalls = Int($sBalls) If $iBalls < 1 Then Exit EndIf ; Get recursive results _AddResults($iCups, $iBalls, "") MsgBox(64, "Results", $sResults) ; ---------------------------------------- ; Function _AddResults() ; Recursively adds possible combinations of balls in cups ; $iC = no. of cups remaining ; $iB = no. of balls remaining ; $sLine = current string being assembled ; ---------------------------------------- Func _AddResults($iC, $iB, $sLine) $sLine &= "|" If $iC = 1 Then ; Last cup, end of line $sResults &= $sLine & $iB & "|" & @CRLF Else ; Not the last cup, recurse For $b = $iB To 0 Step -1 _AddResults($iC - 1, $iB - $b, $sLine & $b) Next EndIf EndFunc Happy New Year! I jsut need the number of possibilites edited your ex script to this and ghot what i wanted: expandcollapse popupGlobal $sCups, $iCups, $sBalls, $iBalls, $sResults = "",$pos ; Get number of cups $sCups = InputBox("Cups", "Enter number of cups: ") If @error Then Exit Else $iCups = Int($sCups) If $iCups < 1 Then Exit EndIf ; Get number of balls $sBalls = InputBox("Balls", "Enter number of balls: ") If @error Then Exit Else $iBalls = Int($sBalls) If $iBalls < 1 Then Exit EndIf ; Get recursive results _AddResults($iCups, $iBalls, "") MsgBox(64, "Results","pos: " & $pos & " result: " & $sResults) ; ---------------------------------------- ; Function _AddResults() ; Recursively adds possible combinations of balls in cups ; $iC = no. of cups remaining ; $iB = no. of balls remaining ; $sLine = current string being assembled ; ---------------------------------------- Func _AddResults($iC, $iB, $sLine) $sLine &= "|" If $iC = 1 Then ; Last cup, end of line $sResults &= $sLine & $iB & "|" & @CRLF Else ; Not the last cup, recurse For $b = $iB To 0 Step -1 _AddResults($iC - 1, $iB - $b, $sLine & $B) $pos = $pos + 1 Next EndIf EndFunc Edited December 31, 2008 by TooManySecrets Link to comment Share on other sites More sharing options...
mmavipc2 Posted December 31, 2008 Share Posted December 31, 2008 This makes a good exercise in recursion: expandcollapse popupGlobal $sCups, $iCups, $sBalls, $iBalls, $sResults = "" ; Get number of cups $sCups = InputBox("Cups", "Enter number of cups: ") If @error Then Exit Else $iCups = Int($sCups) If $iCups < 1 Then Exit EndIf ; Get number of balls $sBalls = InputBox("Balls", "Enter number of balls: ") If @error Then Exit Else $iBalls = Int($sBalls) If $iBalls < 1 Then Exit EndIf ; Get recursive results _AddResults($iCups, $iBalls, "") MsgBox(64, "Results", $sResults) ; ---------------------------------------- ; Function _AddResults() ; Recursively adds possible combinations of balls in cups ; $iC = no. of cups remaining ; $iB = no. of balls remaining ; $sLine = current string being assembled ; ---------------------------------------- Func _AddResults($iC, $iB, $sLine) $sLine &= "|" If $iC = 1 Then ; Last cup, end of line $sResults &= $sLine & $iB & "|" & @CRLF Else ; Not the last cup, recurse For $b = $iB To 0 Step -1 _AddResults($iC - 1, $iB - $b, $sLine & $b) Next EndIf EndFunc Happy New Year! Can you make a faster algorithim that only calculates the number of possibilities? Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 31, 2008 Share Posted December 31, 2008 Can you make a faster algorithim that only calculates the number of possibilities?Surely it can be derived mathematically without working out individual combinations at all. But I'm not enough of a mathematician to tell you the formula.You're not try to get your Statistics homework done for you... are you? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now