Combination probability - probability

I have a list of integers [1,2,3,4,5,6,6,6,6,7,7,7]
I have to select 3 numbers at random. What is the probability that atleast one of the selected number is 6?
Please help on how to proceed with this query. I have tried combination formula but still not able to arrive the result. The result for this is 0.745454545454

As this looks like a homework, and you don't ask for the answer but only help for how to proceed, I would like to give only an idea.
You can find the probability of not having 6 selected, and then subtracting this probability from 1.

First compute the probability of the Complementary event when no 6 is selected. Then subtract this value from 1.
The solution is:
1 - (combination(8,3) / combination(12,3)) = 0.7454545454545

Related

Find a 4 digits number without repetition

I've received a question to solve. I've manage to solved it by hand but couldn't find an exact algorithm to solved it.
The question:
The user insert a 4 digits number without repetition of any of the digits (can have a leading 0).
The algorithm needs to find this number.
There is a check function that received a 4 digits number and returns how many numbers were correct, and how many of the numbers were in the correct place without overlap, and without mentioning which one is.
The system has 7 tries.
For example:
The user insert the Number: 0584
If the system sends the number: 6549
The return would be:
1 item in place
1 item is correct
I would try to solve this puzzle in 2 steps:
Try to find out which 4 digits the solution contains of.
For the miss-placed positions find the right order.
I'm not sure if there is an algorithm to always find the solution within 7 requests, but this way you should at least get closer to a solution.
It's a puzzle, so think about digit-patters that reveal as much information about the solution as possible. And try to extract as much information from the answer to reduce the number of still possible solutions.

Sack with different weights, what has to be the diff for it to work

Question: I have a sack which can carry some weight, and number of items with weight and i want to put as much weight as possible in the sack to carry, after some thought I have got into a conclusion, I take the highest weight every time and put into the sack, intuitivaly that it will work if the weights that are given are incremented atleast by multiplication of 2. For e.g. 2 4 8 16 32 64..
Can anyone help me prove if I am right or wrong about that? I have also an intuition about that, would love to hear urs.
Note: thought about saying that the sum of the previous numbers wont be bigger of the current nunber.
Yes, described greedy algorithm will work for powers of two.
Note that partial sum of geometric sequence 1,2,4,8,16..2^(k-1) is 2^k-1, that is why you always should choose the largest possible item - it is always bigger than any sum of smaller items.
In mathematical sense set of 2's powers forms matroid
But it would fail in general case (example - 3,3,4 and sum 6). You can learn for dynamic programming to solve this problem with integer weights. It is similar to knapsack problem with unit item costs.

n-place mastermind variation algorithm

A few days ago I came across such a problem at the contest my uni was holding:
Given the history of guesses in a mastermind game using digits instead
of colors in a form of pairs (x, y) where x is the guess and y is how
many digits were placed correctly, guess the correct number. Each
input is guaranteed to have a solution.
Example for a 5-place game:
(90342, 2)
(70794, 0)
(39458, 2)
(34109, 1)
(51545, 2)
(12531, 1)
Should yield:
39542
Create an algorithm to correctly guess the result in an n-place
mastermind given the history.
So the only idea I had was to keep the probability of each digit being correct based on the correct shots in a given guess and then try to generate the most possible number, then the next one and so on - so for example we'd have 9 being 40% possible for the first place (cause the first guess has 2/5=40% correct), 7 being impossible and so on. Then we do the same for other places in the number and finally generate a number with the highest probability to test it against all the guesses.
The problem with this approach, though, is that generating the next possible number, and the next, and so on (as we probably won't score a home run in the first try) is really non-trivial (or at least I don't see an easy way of implementing this) and since this contest had something like a 90 minute timeframe and this wasn't the only problem, I don't think something so elaborate was the anticipated approach.
So how could one do it easier?
An approach that comes to mind is to write a routine that can generally filter an enumeration of combinations based on a particular try and its score.
So for your example, you would initially pick one of the most constrained tries (one of the ones with a score of 2) as a filter and then enumerate all combinations that satisfy it.
The output from that enumeration is then used as input to a filter run for the next unprocessed try, and so on, until the list of tries is exhausted.
The candidate try that comes out of the final enumeration is the solution.
Probability does not apply here. In this case a number is either right or wrong. There is no "partially right".
For 5 digits you can just test all 100,000 possible numbers against the given history and throw out the ones where the matches are incorrect. This approach becomes impractical for larger numbers at some point. You will be left with a list of numbers that meet the criteria. If there is exactly one in the list, then you have solved it.
python code, where matches counts the matching digits of its 2 parameters:
for k in range(0,100000):
if matches(k,90342)==2 and matches(k,70794)==0 and matches(k,39458)==2 and matches(k,34109)==1 and matches(k,51545)==2 and matches(k,12531):
print k
prints:
39542

Arranging groups of people optimally

I have this homework assignment that I think I managed to solve, but am not entirely sure as I cannot prove my solution. I would like comments on what I did, its correctness and whether or not there's a better solution.
The problem is as follows: we have N groups of people, where group ihas g[i]people in it. We want to put these people on two rows of S seats each, such that: each group can only be put on a single row, in a contiguous sequence, OR if the group has an even number of members, we can split them in two and put them on two rows, but with the condition that they must form a rectangle (so they must have the same indices on both rows). What is the minimum number of seats S needed so that nobody is standing up?
Example: groups are 4 11. Minimum S is 11. We put all 4 in one row, and the 11 on the second row. Another: groups are 6 2. We split the 6 on two rows, and also the two. Minimum is therefore 4 seats.
This is what I'm thinking:
Calculate T = (sum of all groups + 1) / 2. Store the group numbers in an array, but split all the even values x in two values of x / 2 each. So 4 5 becomes 2 2 5. Now run subset sum on this vector, and find the minimum value higher than or equal to T that can be formed. That value is the minimum number of seats per row needed.
Example: 4 11 => 2 2 11 => T = (15 + 1) / 2 = 8. Minimum we can form from 2 2 11 that's >= 8 is 11, so that's the answer.
This seems to work, at least I can't find any counter example. I don't have a proof though. Intuitively, it seems to always be possible to arrange the people under the required conditions with the number of seats supplied by this algorithm.
Any hints are appreciated.
I think your solution is correct. The minimum number of seats per row in an optimal distribution would be your T (which is mathematically obvious).
Splitting even numbers is also correct, since they have two possible arrangements; by logically putting all the "rectangular" groups of people on one end of the seat rows you can also guarantee that they will always form a proper rectangle, so that this condition is met as well.
So the question boils down to finding a sum equal or as close as possible to T (e.g. partition problem).
Minor nit: I'm not sure if the proposed solution above works in the edge case where each group has 0 members, because your numerator in T = SUM ALL + 1 / 2 is always positive, so there will never be a subset sum that is greater than or equal to T.
To get around this, maybe a modulus operation might work here. We know that we need at least n seats in a row if n is the maximal odd term, so maybe the equation should have a max(n * (n % 2)) term in it. It will come out to max(odd) or 0. Since the maximal odd term is always added to S, I think this is safe (stated boldly without proof...).
Then we want to know if we should split the even terms or not. Here's where the subset sum approach might work, but with T simply equal to SUM ALL / 2.

Algorithm for optimal "intersection" of two results?

I have two results and like to get the best "order" of both these.
Example:
We have a race with 5 people in one race, and 7 in another. The outcome is:
Race 1.
1. Karl
2. Fred
3. John
4. Peter
5. Sid
Race 2.
1. Steven
2. John
3. Karl
4. Peter
5. Aron
6. Fred
7. Kevin
The questin is: whats the top 7 of both these races?
Its quite obvious that that nr 1 is Karl in this case, since he hold one 1st place and one 3rd, which is better than Johns second and third place. However, Steven could be equally good but he did only participate in one race and should suffer some kind of penalty for that.
What are the known algorithms for this problem? Are there any trivial solutions? I just can't figure it out
You can relate the positions to weights (think of it as points)
For instance 1st position has a weight of 20. 2nd has 18. 3rd 16, etc.
Participation miss could relate to a weight of -5.
You can adjust the numbers as required.
To find the final result you add everyone's weights and compare the numbers.
I think it should work..
Another approach would be to create an ordering of the top nodes which are consistent with the ordering of the previous races. This could be done by using a max-flow algorithm.
A naive solution would be to have some kind of ID for all the players. Go through both lists and add any new IDs you come across to a separate list, called Positions for example. Set all values for these IDs to some large number that can not be a race position, call it BIG_VAL (eg. 100). Go through the first list and mark all the positions as the new values in the Positions list. This was just the first race, so there is nothing special here. Then go through the second list and add the second position results for those IDs into the Positions list. For the IDs that don't occur, add another BIG_VAL to their result. The list will now have the race positions in order, all that remains is to sort them. Karl will be 4, John will be 5, Fred will be 8, and so on in this list:
http://bit.ly/fvYtal

Resources