service{ const html Welcome =
Welcome to the matches game!
Please choose a pack with matches in it from 1 to 5:
Pack 1
Pack 2
Pack 3
Pack 4
Pack 5
Please choose the number of matches you want to get out of
the pack(smaller than the # in the pack and greater than zero:
;
const html Fin =
; int seed, total; int nextRandom(int x) { int current; if(x == 1) return(1); seed = ((25173*seed + 13849) % x) + 1; return(seed); } int Manipulate_Pack(int pack, int j) { if(j>pack || j<1){ show Illegal; exit Fin; } else pack = pack - j; if (pack == 0) total = total -1; return (pack); } void check(int x){if(x == 0) total = total - 1;} session Play() { int i, j; int pack1, pack2 , pack3, pack4, pack5; total = 5; pack1 = pack2 = pack3 = pack4 = pack5 = 10; show Welcome; seed = 7; while( pack1 !=0 || pack2 != 0 || pack3 != 0 || pack4 != 0 || pack5 != 0) { show plug Pick [pack1 = pack1, pack2 = pack2, pack3 = pack3, pack4 = pack4 , pack5 = pack5] receive[i = pack_choice, j = no_choice]; if(i==1){ pack1 = Manipulate_Pack(pack1, j);} if(i==2){ pack2 = Manipulate_Pack(pack2, j); } if(i==3){pack3 = Manipulate_Pack(pack3, j);} if(i==4){pack4 = Manipulate_Pack(pack4, j);} if(i==5){pack5 = Manipulate_Pack(pack5, j); } if(total == 0) {show Won; exit Fin;} if(total == 1){ if(pack1 != 0) pack1 = 0; if(pack2 != 0) pack2 = 0; if(pack3 != 0) pack3 = 0; if(pack4 != 0) pack4 = 0; if(pack5 != 0) pack5 = 0; } if(pack1 != 0){ pack1 = pack1 - nextRandom(pack1); check(pack1); } else if(pack2 != 0){ pack2 = pack2 - nextRandom(pack2); check(pack2); } else if(pack3 != 0){ pack3 = pack3 - nextRandom(pack3); check(pack3); } else if(pack4 != 0){ pack4 = pack4 - nextRandom(pack4); check(pack4); } else if(pack5 != 0){ pack5 = pack5 - nextRandom(pack5); check(pack5); } } show Lost; exit Fin; } }