This routine finds the mean of an arbitrary number of reals: real proc MEAN(event_type ERROR; reals X); (real SUM:=0.; int COUNT:=0; while ~empty X for COUNT from 1 by 1 do SUM:=SUM+; string BANK:="left"; int I; equ M:=simple,C:=simple; simple bag LEFT:=B, RIGHT:=B<>,BOAT; simple bag loc SIDE:=@LEFT; bool proc BAD(simple bag X); num(C,X)>num(M,X)&num(M,X)~=0; *ALLBACK:=*BTCONT:=true; do ignore ACTIONS*L<"Empty the boat.">; BOAT:=B<>; for I in <1,2> try; for to I do for X in &SIDE try; &SIDE:=&SIDE-B; BOAT:=BOAT+B; ignore ACTIONS*L<"Put a "+(if X=C then "cannibal" else "missionary") + " into the boat."> od; if BAD(&SIDE) | BAD(BOAT) then fail fi; if SIDE=@LEFT then SIDE:=@RIGHT; BANK:="right"; else SIDE:=@LEFT; BANK:="left" fi; &SIDE:=&SIDE+BOAT; if BAD(&SIDE) then fail fi; ignore ACTIONS*L<"Cross to the "+BANK+" bank."> until size(RIGHT)=6 od; for BANK in ACTIONS do line(BANK) od corp;