There's a table with four coins with random initial faces. You're blindfolded and each turn, you have to choose a subset of coins to flip over. Your objective is to make them all face the same way.
There is also someone else who, after you flip some coins, will rotate the table as much as they want during their turn. Their objective is to not let you win. Since you're blindfolded, you're not aware of how much the table has been rotated.
A sample game would look like: You go first, flip the top and left coins. Then, the adversary rotates the board 180 deg. Then it's your turn and you flip the bottom and right coins ( in this case, zero work was done).
What is the strategy to win?
I'm using the following moves:
1 : Flip a single coin (eg: the one in front of you)
D : (Diagonal) Flip two opposite coins (the one in front of you, the one in front of your adversary)
A : (Adjacent) Flip two adjacent coins (the one in front of you and the one on the right)
Then the sequence
D A D 1 D A D
passes always though a winning state !
This is proved by case analysis.
You don't start with a winning position. So there are at least one head and one tail coins.
I assume first that there are 2 heads and 2 tails.
Remark that, in this case, any D and A move either wins or keep 2 heads and 2 tails.
2a. If the two head are facing then D wins.
2b. If not then D doesn't change the state upto rotation (two adjacent head coins)
Then if you do A, either you win or you get two facing heads. So you arr back in 2a.
Summary : D A D wins if they are 2 heads and 2 tails.
If not, D A D keeps a state with one coins of a sort and three of the other.
So if D A D didn't win you know that you are in such a state.
Now if you just flip a coin, either you win or you end up with a 2 heads and 2 tails state. Therefore another D A D wins.
So
D A D 1 D A D
always wins !!!
I dont know in English, but in French this is a classical in automaton called "Le barman aveugle" (the blind bartender). There are a lot of page about this problem. EG:
This page
EDIT: I just dicovered an English page on Wikipedia
Note that in every turn there are precisely 2 subsets that are winning moves. The total number of subsets is 2^4=16. Therefore, in every turn there is a probability of 2/16=1/8 to win instantly if you randomly choose a subset, where the universe is {1, 2, 3, 4} and 1 denotes the coin in front of you, 2 its neighbor under clockwise order and so on.
If the number of rounds is unbounded, one winning strategy is to repeatedly 'guess' a subset of the coins to flip over. The probability to win within the first n turns is 1 - (7/8)^n. The probability is strictly increasing in n and is asymptotically 1. You will win p-a.s.
Your moves are independent of each other: Your strategy does not incorporate any information from previous turns.
Your adversary does not have any strategy to counter your efforts. Turning the table amounts to relabelling the coins in the set you draw from. You do not exploit the labelling in choosing the subset, therefore the adversary's actions cannot foil your strategy. In particular, after your k-th turn, each of your possible subset choices in turn k+1 has the same likelihood to occur and does not depend on the adversary's action.
To be precise, the relabelling is not completely arbitrary - only 4 out of 4^4=256 possible relabellings can be implemented by turning the table. Again, while this may imply a more efficient strategy for you, it cannot harm you as you do not exploit the information.
Refinement
Never choose 0 or 4 coins as your subset as this can never be a winning move (these moves only ever produce a set of coins with the same face on top if you start with such a configuration). Thus the probability for an instant win is now 2/(16-2)=1/7, with the probability to win within the first n turns becoming 1 - (6/7)^n. This refinement has no effect on the general reasoning behind the strategy.
Related
I have almost no knowledge of multithreading, but a problem I am working on right now perhaps is a good opportunity to get started on learning concurrency and parallelism. I am hoping to get some pedagogical advice directed towards my specific problem.
The Abstract Problem
In abstract, I would like to write a program with N tasks such that
N is predetermined.
Some partial information computed by the n-th task is enough for the (n+1)-th task to start. However, we don't know beforehand how much partial information is enough. The n-th task is responsible for determining that.
So what I am hoping for is to have N threads, and the important point is that the n-th thread figures out during runtime when the (n+1)-th thread can begin. Can this be achieved with multithreading? I am familiar with Java and C++. What tools/libraries should I look into to begin with?
The Concrete Problem
The sieve of Eratosthenes is an algorithm for finding prime numbers up to a given upper limit by successively finding composite numbers as multiples of known primes. Most composite numbers have more than one prime factor and will be found multiple times. So looking for multiples of 2 and 3 in parallel can cause data race. However, the algorithm can be modified so that each composite number is found exactly once. Suppose we want to find all primes between 2 and K.
Mark 2 as prime and mark all multiples of 2 as composite. We have marked all the numbers whose smallest prime factor is 2.
The smallest unmarked number is 3. So 3 is the next prime number after 2. Multiply 3 with all numbers less than K/3 that are left unmarked after step 1. The products are all the numbers whose smallest prime factor is 3. Mark these numbers.
The smallest unmarked number is now 5. So 5 is the next prime after 2 and 3. Multiply 5 with all the numbers less than K/5 that are left unmarked after step 2 and we find all the numbers whose smallest prime factor is 5. Mark these numbers.
Repeat until we have reached floor(sqrt(K)).
Note that, for instance, step 3 can begin while step 2 is running. Early on in step 2 we find 5 as the smallest unmarked number and hence the next prime number. Therefore, once all numbers less than K/5 have been marked during step 2, we then know step 3 can begin. Step 3 will not interfere with step 1 or 2 because each composite number is found exactly once.
Good day,
As homework ive got to create a strategy in excel, that will be put up against the strategies of others. It is applied to a game that works as follows;
Two strategies are put up against each other
You have the option to put a coin in an envelope.
If you put a coin in your score drops by 1.
If you dont put a coin in your score remains the same.
The players make their decisions simltaneously then you swap envelopes with the opponent.
If you dont get a coin in the envelope you get 0.
If there is a coin in the envelope you get 2. Meaning, if you didnt put one in and there is a coin, you get plus 2, and if you did you and you get a coin your score changes by plus 1.
If no one puts a coin in ,the score doesnt change so plus 0.
If you put one in and the opponent didn't your score decreases by 1.
The game is to be played for 10000 rounds, with the objective to
maximize your own profit and minimize the profit of the opponent.
I have added an image of my work so far, my tracked score is currently higher, than that of a randomized opponent, yet i remain curious, wether someone can beat my strategy or if anyone has any ideas for optimization.
thanks in advance
What I tried first was to cooperate in the first round, after which i decided to copy the move of the opponent in the previous round for 5 rounods. Then I started with the thought of, he gave one in the first round and the sum of his past 5 rounds where bigger than 2 , he decided to cooperate, so we give one, otherwise we dont. Then until the end i procede with:
=IF(AND(B10=1;SUM(B6:B10)>2);1;IF(AND(SUM(D9:D10)=0;SUM(B4:B8)>2);1;0))
so if he gave one in the previous round and the sum of his past 5 rounds are is bigger than two we give one, if not the we see if i did not give twice in a row because he did not give enough( for five rounds > 2) then we give one, otherwise we give 0.
Here is the code for the scoring that i used.
=IF(AND(A2=C2;SUM(A2:C2)=2);1;IF(AND(A2=0;C2=1);2;IF(AND(C2=0;A2=1);-1;0))
The tracked score consists of the sum, of the previous rounds and the current round.
I expect to profit more than the opponent, but so far the opponent has only been a random number generator , and would like some help with improving the strategy.
I got stuck in a problem. The overall problem statement is big. I have solved the other pieces of it.
Got stuck in one piece.
Given a string containing some dashes('-') and some character lets say ('A'). Also, we are given with cost C to shift a character to its adjacent place. We need to find minimum cost such that all 'A' characters are grouped.
Example1: A-A--A---A and cost = 10
Minimum cost to group all 'A's would be: 80
Example2: AAAA------A and cost = 10
Minimum cost to group all 'A's would be: 60
Hint: for the cost to be minimum possible, one of the median As (2nd or 3rd of 4 in your first example, 3rd of 5 in your second example) can be left in place. Using this, you can compute the cost in O(n), where n is either the length of the string or the number of As, whichever is your input format.
I don't think this problem needs dynamic-programming.
You only need to move all A's towards the median A because this is the least total distance between all A's.
Just make sure not to move the media A. If the A at the median is moved to the right, each of the A's to its left will have to move one more step and each of the A's to its right will have to move one step less. This should cancel out, but you already added one unneeded step.
I've read many articles about the Monte Carlo algorithm for approximating the preflop equity in NL holdem poker.
Unfortunately, it iterates over only a few possible boards to see what happens. The good thing about this is that you can put in exact hand ranges.
Well, I don't need exact ranges. It's good enough to say "Top 20% vs Top 35%".
Is there a simple formula to tell (or approximate) the likelihood of winning or losing? We can ignore splits here.
I can imagine that the way to calculate the odds will become much simpler if we just using two (percentile) numbers instead of all possible card combinations.
The thing is, I don't know if for example the case "Top 5% vs Top 10%" is equal to "Top 10% vs Top 20%".
Does anyone know of a usable relation or a formula for these inputs?
Thanks
Okay, I've made a bit analytical work and I came up wit the following.
The Formula
eq_a(a, b) := 1/2 - 1/(6*ln(10)) * ln(a/b)
Or if you like:
eq_a(a, b) := 0.5 - 0.072382 * ln(a/b)
Where a is the range in percent (0 to 1) for player a. Same for b.
The function outputs the equity for player a. To get the equity for player b just swap the two ranges.
When we plot the function it will look like this: (Where a = x and b = y)
As you can see it's very hard to get an equity greater than 80% preflop (as even AA isn't that good mostly).
How I came up with this
After I've done some analysis I became aware of the fact that the probability of winning is dependent on just the ratio of the two ranges (same for multiway pots).
So:
eq_a(a, b) = eq(a * h, b * h)
And yes, Top 5% vs Top 10% has the same equities as Top 50% vs Top 100%.
The way I've got the formula is I've done some regressions on sample data I've calculated with an app and picked the best fit (the logarithmic one). Then I optimised it using special cases like eq_a(0.1, 1)=2/3 and eq_a(a, a)=1/2.
It would be great if someone will do the work for multiway preflop all-ins.
I'm going to try to explain this the best that I can.
Right now I have a spreadsheet with a list of football players, each of which has an assigned salary and projected point total for the week.
My goal is to use Solver or some other method to determine the best combination of players to maximize the projected point total while staying under a salary cap.
In this example I have 4 separate player lists, like this:
QB: Player A, Player B, Player C...Player N
RB: Player a, Player b, Player c...Player N
WR: Player X, Player Y, Player Z...Player N
TE: Player x, Player y, Player z...Player N
I need the best combination that includes 2 QBs, 2 RBs, 2 WRs, 1 TE, and 2 "Flex", which means any of RB/WR/TE.
I have tried using Solver to maximize the projected point total, but the variable fields in this case would be the Player's Names and it seems like the variable field needs to be a number, not a list of strings.
Any ideas?
My favorite kind of question :)
Here is the model setup:
Top table shows the decision variables: = 1 if player i = A, B, ..., N of list L = QB, .., TE is selected, =0 otherwise.
Entries in column R, (next to the top table) are the sums of each row. These must be constrained with the numbers in column T. Cell R7 is the total sum of players, which should be 9: 2 flexible and 7 as per the individual list requirements.
Middle table shows the salaries (randomly generated between 50,000 and 150,000). The Sum of Salaries formula is =SUMPRODUCT(C11:P14,C3:P6). The idea here is that only the salaries of players that are selected are taken into account. This SUMPRODUCT should be constrained with the budget, which is in cell T14. For my experiment, I put it equal to 80% of the total sum of all salaries.
Objective: Bottom table shows the projected points for each player. The formula in cell R22 is =SUMPRODUCT(C19:P22,C3:P6) (same logic as with salaries above). This is the value to be maximized.
Solver Model shown below:
I suggest selecting Simplex LP and going to Options and setting the Integer Optimality to zero (0).
Result:
Solver manages to find an optimal solution. The problem is really small and it is very quick. Solver works with up to 200 variables and 100 constraints, for large problems you will need the (commercial) extended version:
Of course, you can just order the real player names so that they fit this setting. For example, if you sort the players of each list alphabetically, then (Player A, QB) = first player of team QB, etc.
I hope this helps! Let me know if you would like me to upload the file for you.
Best,
Ioannis
Excel's solver is built on numerical methods. Applying to a domain that consists of discrete values, like strings or football players is probably going to fail. You should consider writing a brute force solver in a "real" programming language, like c#, java, python, ruby, or javascript. If there are performance problems, then optimize from there.
Solver won't work here because it's not a numeric solution you're after.
Make a spreadsheet that has every possible combination of position players (that meet your criteria) on each row. Then make an Excel formula that calculates projected point total based on the players in that row. Sort the spreadsheet by your projected point column.