Sign in to follow this  
Followers 0
TooManySecrets

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

7 posts in this topic

#1 ·  Posted (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 by TooManySecrets

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by igotandrew

Share this post


Link to post
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.

i dont understand your code?

it not cup 1 and cup 2 it's

1 cup 2 cups.

you get it

?

Share this post


Link to post
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
_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

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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
_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:

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
_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 by TooManySecrets

Share this post


Link to post
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
_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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0