|
 |
On 22-9-2009 21:58, Warp wrote:
> andrel <a_l### [at] hotmail com> wrote:
>>> 2) Assume you have an array of 24 integers. Each element of that array
>>> can get a value between 0 and 7. Thus the total amount of different contents
>>> for such as an array is 8^24, which is approximately 4*10^21.
>>>
>>> Now assume that you fill the array with some values and then calculate
>>> all the possible permutations of that array. The amount of permutations
>>> for 24 elements is 24!, which is approximately 6*10^23.
>>>
>>> Now here's the apparent paradox: The total amount of different contents is
>>> about 4*10^21, and naturally all those permutations should be among them as
>>> well. How come the total amount of permutations, 6*10^23, is way larger
>>> than the total amount of possible different array contents?
>
>> 8 is less than 24
>
> So? How does that answer the question?
that is obvious, I would think.
>>> 3) Assume two people, person A and person B, who want to decide who gets
>>> a price by tossing a coin.
>>>
>>> Person A is a bad loser and a bully, so if he loses he says "I said it's
>>> two out of three". So they play it like that. If A loses again, he says
>>> "I said it's three out of five", and so on, until he wins.
>>>
>>> How many tosses is this game expected to last, in average?
>
>> same answer as: what will the average number if boys be if every pair of
>> parents continues getting children until they get a boy.
>
> It isn't. It would be if the game would have been "we throw the coin
> until it gives heads". However, that's not how the game goes.
Ok I read that wrong. Can you give an algorithm for 'and so on'?
1 2 3 4 5..
- - - - -
2 3 5 8 13...
or
1 2 3 4 5 ..
- - - - -
2 3 5 7 11...
or
?
>>> 4) By their nature, factorials tend to accumulate trailing zeroes. For
>>> example, 5! (120) has one trailing zero, 10! (3628800) has two trailing
>>> zeroes, 25! (15511210043330985984000000) has six trailing zeroes, etc.
>>>
>>> Give a (non-recursive) mathematical function which, for an integer n,
>>> gives the number of trailing zeroes in n!.
>
>> just count the number of 5s, 25s, 125s etc
>
> Firstly, the question didn't ask for an algorithm to calculate the number
> of zeros (which is what the "non-recursive" part more or less rules out).
> It asked for a closed-form function which tells the number of zeros.
>
> Secondly, your algorithm is flawed. 10! has two zeros and only one 5 as
> a factor.
No it has 2 both 10 and 5 have a factor of 5. So if you want your
algorithm:
sum_k floor(x/(5^k)) over all k from 1 till 5^k<=x
Post a reply to this message
|
 |