Deal z
z&|
k=22:number of boxes
9 :7:7:
(6,12;"22 BOXES":502
(,9 ,10
;"NO QUESTIONS":502
2+12,11;"EXCEPT ONE":90Z
<&15,8;"DEAL OR NO DEAL?"
d$p(k):p$(k,7):prize amounts
n:n=1 k
xp(n)
*p$(n)=(" "p(n)<1000)+"`"+(p(n))
5p(n)<1 p$(n)=" "+((p(n)*101e))+"p"
1101, not 100, or else there are rounding errors
n
B0.01z#
=,0.1}L,0.5,1,5,10
,502
4100d,250,500,750,1000
;3000,5000,10000',15000:,20000 N
?35000,50000P,75000|,100000CP,250000t$
c(k):Contents of boxes
$b(k):List boxes in order of value
Choose your initial box
4:4:
&n=1 k/2
0,n*2-2,0;1;p$(n);
:"" ";n;22;n+k/2;" ";
D2;p$(n+k/2)
Nn
Xyours=(*22)+1
bW2*(yours-1)-k*(yours>k/2),8+14*(yours>k/2);"";
v8;8;yours;" "
=""600X
.#1;" You are playing with box ";yours
`2*(yours-1)-k*(yours>k/2),8+14*(yours>k/2);1;yours
Assign prizes to boxes
n=k 1 -1
m=(*n)+1
t=0
t=t+1
m=m-b(t)
m>0750
b(t)=n
*c(t)=p(n)
4n
>boxes=22:picks=5
H3000
Main game loop
"Choose a box",choice
choice=(choice)
fchoice<1 choice>k #1;1,9 ;"Learn to count":1,-24:2000
wchoice=yoursc(choice)=0 #1;1,4;"That box has already gone":1,-24:2000
4
Y2*(choice-1)-k*(choice>k/2),8+14*(choice>k/2);" "
44000:4800
>
502
H*boxes=boxes-1:picks=picks-1
Rpicks>0 2000
3300
4
/#1;1,14;"Hello?":75K
<#1;1,6;"That's very generous":75K
5000
#1;1,0,,
3000
?5,11;"THE BANKER";7,11;"OFFERS YOU"
(9 ,13
; 7;"`";banker
100d
$315,12; 7; 1;" DEAL "
.17,15;"or"
8319,12; 0; 1;"NO DEAL?"
B#23658j\,8:Caps lock on
`="D"2900T
j"N"2400`
t3000
~picks=3
boxes>2 2000
FWe want a test that will always offer a swap if the `250K is in play
Mand will also offer a swap if a large sum of money stands to be won or lost
MIf this is the case, the larger of these two expressions will be big enough
>The smaller one is irrelevent - I only include both to avoid
*having to calculate which one is bigger.
8c(yours)*c(yours)/c(lastone)300000 |2600(
<c(lastone)*c(lastone)/c(yours) < 300000 |2800
(3300
11)
!4,12;p$(b(choice))
502
Remove the prize
c(choice)=0
"b(choice)>k/2 4900$
n=1 8
Y(b(choice)*2-2),0; 1;p$(b(choice))(n 7); 4;" ";
3
n
$n=7 0 -1
.U(b(choice)*2-2-k),31-n; 4;" "; 2;p$(b(choice))(n)
8 3
Bn
L
Calculate banker's offer
boxes=2 5500|
FA fair offer would be the arithmetic mean of all the remaning prizes
Gie the sum of the remaining money divided by the number of boxes left
@Instead of dividing by 5'8'11'14'17, we are going to divide by
05*2'8*2.5'11*3'14*3.5'17*4 - This unfair offer
61) Provides a strong incentive not to deal too early
@2) Rewards the player for not knocking out the largest prizes,
( even fairly early in the game.
Pbanker=0
Zn=1 k
nbanker=banker+(c(n))
xn
-banker=banker*6/(boxes+7)/boxes
6000p
|$There are now only two boxes left.
KWe need an offer that is less than the arithmetic mean of the two prizes,
"but more than the smaller prize.
?The geometric mean (square root of the products) is suitable.
PHowever, if one prize is next to nothing, the geometric mean will be derisory.
eg `250K and 1p gives `50.
8The formula given, where C is a dimensionless constant
1) is dimensionally correct
H2) ensures the offer cannot be less than the bigger prize divided by c
K3) doesn't depend on which prize is the bigger, and which is the smaller.
a4) changes smoothly (not abruptly) as the ratio varies anmd different terms come to predominate
HIf p1=p2=p, the calculated prize rises from p to p times (1+(1/(c^2)),
HA negligible increase that is swallowed up by rounding down the offer.
JIf c1>c2, the term (c2/c)^2 is negligible. But it's easier to include it
1than to calculate which of c1 and c2 is bigger.
Dn=1 k
N,nyours c(n)>0 lastone=n:c2=c(n)
X-There is only one possible value of lastone
bn
l
c1=c(yours)
v8c=10
:This is a suitable value for the parameter
'banker=((c1*c2)+(c1*c1+c2*c2)/(c*c))
p,Round the offer to two significant figures
zb$=((banker))
b$(3 )="0000"
banker=(b$)
,banker=banker+banker:so it can't be zero
X
End of game
b500
l5:5:
v#1; 1;m$;banker,
choice=yours:4000
0: