/* Three card problem in Picat. https://twitter.com/MathsEdIdeas/status/1769785845970796935 """ Three cards are dealt face down from a normal deck. Two are turned over and are the same colour. What is the probability that the third card is the same colour as the first two? HT Martin Gardner @WWMGT, but was his solution correct? [ 9 of spades Queen of clubs back of a card ] """ Note: color is black or red (not clubs, hearts, spades, diamonds). Result (exact from my Gamble model): (#f : 13/25 (0.52)) (#t : 12/25 (0.48)) This is a port of my Gamble model gamble_three_cards.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. main => go. /* var : p Probabilities: 0: 0.52386763333572606 (7298 / 13931) 1: 0.47613236666427394 (6633 / 13931) mean = 0.476132 */ go ?=> reset_store, run_model(30_000,$model,[show_probs_rat,mean]), nl. go => true. model() => N = 52, Mod = 2, % Pick three cards [C1,C2,C3] = random_integer1_n(N,3), observe(C1 != C2, C1 != C3, C2 != C3, % different numbers (C1 mod Mod) == (C2 mod Mod)), % first two cards has the same color (black/red) if observed_ok then % Probability that the third card has same color as the other two cards P = cond( (C3 mod Mod) == (C1 mod Mod),1,0), add("p",P) end.