ASM for FUN - #4 SUB [Playing with random numbers generation]

Started by frktons, April 24, 2010, 04:18:07 PM

Previous topic - Next topic

dedndave

i dunno, Frank
i just brought up the calculator and started mashing all the buttons and that's what i came up with - lol
i guess i should use the formula....

P(n,r) = n! / (n-r)!

sooooo, that would be 5,527,200
you are right - my other number was too big   :P

not that it helps us any
the value would only matter if i were going to write the code that way - lol

frktons

Quote from: dedndave on April 25, 2010, 02:18:22 PM
i dunno, Frank
i just brought up the calculator and started mashing all the buttons and that's what i came up with - lol
i guess i should use the formula....

P(n,r) = n! / (n-r)!

sooooo, that would be 5,527,200
you are right - my other number was too big   :P

not that it helps us any
the value would only matter if i were going to write the code that way - lol

Still too big.
According to my calculation it should be 230,300.  :P

Just remember that the following groups are only one group:

1 2 3 4
1 3 2 4
1 4 2 3
1 3 4 2
1 4 3 2
and so on

For the task I'm considering all these different combinations are just one.

Cheers
Mind is like a parachute. You know what to do in order to use it :-)

dedndave

nah - lol
50 x 49 x 48 x 47 = 5,527,200

the first number may be 1 of 50 possible values
the second number may be 1 of 49 possible values
the third number may be 1 of 48 possible values
the forth number may be 1 of 47 possible values

frktons

Quote from: frktons on April 25, 2010, 02:48:59 PM
Quote from: dedndave on April 25, 2010, 02:18:22 PM
i dunno, Frank
i just brought up the calculator and started mashing all the buttons and that's what i came up with - lol
i guess i should use the formula....

P(n,r) = n! / (n-r)!

sooooo, that would be 5,527,200
you are right - my other number was too big   :P

not that it helps us any
the value would only matter if i were going to write the code that way - lol

Still too big.
According to my calculation it should be 230,300.  :P

Just remember that the following groups are only one group:

1 2 3 4
1 3 2 4
1 4 2 3
1 3 4 2
1 4 3 2
and so on

For the task I'm considering all these different combinations are just one.

Cheers


quoting myself  :lol
Mind is like a parachute. You know what to do in order to use it :-)

dedndave

that would only be true if you put each group in order
then, the formula would be

C(n,r) = n! / ( r! (n-r)! )

for generating the groups, we have to consider these as 2 different sets:

5  25  35  45

25  5  35  45

in fact, if we were to generate sorted groups, it would simplify the code   :bg

frktons

As said before:
For the task I'm considering all these different combinations are just one.
So please consider those groups as just one.
A simple pgm to show the possible combinations is attached

Cheers

Frank
Mind is like a parachute. You know what to do in order to use it :-)

dedndave

well - i am not going to argue with you about it - lol
if they are sorted groups, there are fewer groups - easier to generate
if they are unsorted groups, there are 4! times as many possible groups
if we generate sorted groups, it can be even faster


http://www.mathsisfun.com/combinatorics/combinations-permutations.html

frktons

Quote from: dedndave on April 25, 2010, 03:16:04 PM
well - i am not going to argue with you about it - lol
if they are sorted groups, there are fewer groups - easier to generate
if they are unsorted groups, there are 4! times as many possible groups
if we generate sorted groups, it can be even faster


http://www.mathsisfun.com/combinatorics/combinations-permutations.html

Nice educational web-page, thanks Dave.

By the way, we consider
1234 and
4321 as the same combination, but we can generate them in whatever order,
so if it is easier to have them sorted, that's ok as well.

For the task I've in mind, the order doesn't really matter, just that they
are all different from each other  :bg

Let's think about it this way:

numbers 1 to 50 are customers code. It doesn't matter in which order they place an order
into a shop, but "if" they do, no matter how many times per day or how many items.
So a group of 4 customers a day all different from each other can place an order any time in a day.
And we don't know how long it takes between an order and the next of the same customer.

The pgm I proposed RandGen3 creates this kind of combination, with this rules.
How to optimize the generating routine should consider these rules.  :P

Let's see what we get
Mind is like a parachute. You know what to do in order to use it :-)

dedndave

that makes a difference
not only is the code faster, but simpler to write   :P

it brings the "generate 4 at a time" idea back into play
because the code to seperate a single value into 4 ordered numbers is much simpler than unordered

frktons

Let's think about it this way:

numbers 1 to 50 are customers codes. It doesn't matter in which order they place an order
into a shop, but "if" they do, no matter how many times per day or how many items.
So a group of 4 customers a day all different from each other can place an order any time in a day.
And we don't know how long it takes between an order and the next of the same customer.

The pgm I proposed RandGen3 creates this kind of combination, with this rules.
How to optimize the generating routine should consider these rules. 

Let's see what we get
Mind is like a parachute. You know what to do in order to use it :-)