/* Guess the toss in Picat. From https://brainstellar.com/puzzles/probability/108 """ A and B are in a team called AB, playing against C. If AB team wins they win Rs 3, nothing otherwise. The Game: A and B are placed in 2 separate rooms far away. A will toss a coin and B will also toss a coin; A will have to guess the outcome of B's toss and B will guess A's. If both guesses are right, team AB wins Rs 3, nothing otherwise. Should they play the game, by paying Rs 1 at the start? Answer: 1/2 Solution: Let's list down all the possibilities. A B H H H T T H T T Observe that 2 out of 4 times, their coins have the same face, i.e. either both heads or both tails. They can speak their own coin's face as their guess. They win the game with a probability of 1/2. The pay-off will be positive (1/2)*3 - 1 = 0.5 and hence they should play this game. """ Cf my Gamble model gamble_guess_the_toss.rkt This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import ppl_distributions, ppl_utils. import util. main => go. /* My initial take was the no-strategy which is a loss of 1/4. With the strategy mentioned, it's a game of 1/2. var : outcome no strategy Probabilities: 0: 0.7441000000000000 3: 0.2559000000000000 mean = 0.7677 var : profit no strategy Probabilities: -1: 0.7441000000000000 2: 0.2559000000000000 mean = -0.2323 var : outcome strategy Probabilities: 3: 0.5159000000000000 0: 0.4841000000000000 mean = 1.5477 var : profit strategy Probabilities: 2: 0.5159000000000000 -1: 0.4841000000000000 mean = 0.5477 */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => N = 2, [AToss,BToss] = [ cond(flip() == true, h, t) : _ in 1..N], [AGuess,BGuess] = [ cond(flip() == true, h, t) : _ in 1..N], AGuess2 = AToss, BGuess2 = BToss, % No Strategy OutcomeNoStrategy = cond( (AToss == BGuess, BToss == AGuess), 3, 0), ProfitNoStrategy = OutcomeNoStrategy - 1, % Strategy: guess the same as your own toss OutcomeStrategy = cond( (AToss == BGuess2, BToss == AGuess2), 3, 0), ProfitStrategy = OutcomeStrategy - 1, add("outcome no strategy",OutcomeNoStrategy), add("profit no strategy",ProfitNoStrategy), add("outcome strategy",OutcomeStrategy), add("profit strategy",ProfitStrategy).