/* 100 left-hand people problem in Picat. From MindYourDecisions https://www.youtube.com/watch?v=gLN_0K6JnPs """ The British Game Show The 1% Club featured this very interesting riddle for an accumulating jackpot of £97,000. “In a room of 100 people, 99% are left-handed. How many left-handed people have to leave the room to bring that percentage down to 98% ?” """ Perhaps it should have stated _exactly_ 98%? pct_before = 0.99 [leaving = 50,num_left = 50,numLeftHandledLeft = 49] pct_after = 0.98 This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. import cp. main => go. go ?=> N = 100, % Number of people in the room L = 99, % Number of left handed people in the room _R = 1, % Number of right handed people in the room println(pct_before=(L/N)), Leaving :: 1..99, % Number of left handed people leaving the room NumLeft #= N-Leaving, % Number of people left in the room NumLeftHandedLeft #= L-Leaving, % Number of left handle left handed people left 98*NumLeft #= 100*NumLeftHandedLeft, % 98 #= 100*L2/N2, but CP does not like divisions Vars = [Leaving,NumLeft,NumLeftHandedLeft], solve(Vars), println([leaving=Leaving,num_left=NumLeft,numLeftHandledLeft=NumLeftHandedLeft]), println(pct_after=(NumLeftHandedLeft/NumLeft)), fail, nl. go => true.