# divide x number of (insert object here) into y number of (insert object here)

## Recommended Posts

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.

edit:

I just need thr possibilities

Edited by TooManySecrets

##### Share on other sites

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 by igotandrew

##### Share on other sites

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.

it not cup 1 and cup 2 it's

1 cup 2 cups.

you get it

?

##### Share on other sites

This makes a good exercise in recursion:

```Global \$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
MsgBox(64, "Results", \$sResults)

; ----------------------------------------
;   Recursively adds possible combinations of balls in cups
;   \$iC = no. of cups remaining
;   \$iB = no. of balls remaining
;   \$sLine = current string being assembled
; ----------------------------------------
\$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

##### Share on other sites

This makes a good exercise in recursion:

```Global \$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
MsgBox(64, "Results", \$sResults)

; ----------------------------------------
;   Recursively adds possible combinations of balls in cups
;   \$iC = no. of cups remaining
;   \$iB = no. of balls remaining
;   \$sLine = current string being assembled
; ----------------------------------------
\$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:

```Global \$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
MsgBox(64, "Results","pos: " & \$pos & " result: " & \$sResults)

; ----------------------------------------
;     Recursively adds possible combinations of balls in cups
;     \$iC = no. of cups remaining
;     \$iB = no. of balls remaining
;     \$sLine = current string being assembled
; ----------------------------------------
\$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 by TooManySecrets

##### Share on other sites

This makes a good exercise in recursion:

```Global \$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
MsgBox(64, "Results", \$sResults)

; ----------------------------------------
;   Recursively adds possible combinations of balls in cups
;   \$iC = no. of cups remaining
;   \$iB = no. of balls remaining
;   \$sLine = current string being assembled
; ----------------------------------------
\$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?

##### Share on other sites

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

## Create an account

Register a new account

×

• Wiki

• Back

• Git