#BenEzra: A small Maple package for solving #the (obvious generalization of the) #Ben-Ezra riddle: Rabbi Abraham Ben (Ibn) Ezra #was at sea, when a storm started to rage. #There were 15 good guys (Ben Ezra's disciples) #and 15 bad guys (empty-minded and naughty (rekim vepokhazim)) #The Captain said that in order to survive, lots should be #drawn, and 15 passengers should be picked at random to be #thrown into the sea, in order to ease the ship's load, #and enable the remaining passenger's to survive. #The Rabbi replied to the Captain that it was a good idea #and suggested a pseudo-random protocol for drowning, #a-la Josephus: eliminate every 9th (when they are placed #in a circle). This puzzle is mentioned in p. 214 #of the Hebrew Encyclopedia's #enrty on `Even Ezra, Rabbi Abraham'. It first appeared #in Rabbi Moshe Kimkhi's ``Mahalakh Shvilei HaDa'at'' #(c. 1200) #Written by Doron Zeilberger, Temple University ,zeilberg@math.temple.edu. #Please report bugs to zeilberg@math.temple.edu print(`BenEzra: A small Maple package for solving`): print(`the (obvious generalization of the)`): print(`Ben-Ezra riddle: Rabbi Abraham Ben (Ibn) Ezra`): print(`was at sea, when a storm started to rage. `): print(`There were 15 good guys (Ben Ezra's disciples) `): print(` and 15 bad guys (empty-minded and naughty (rekim vepokhazim))`): print(`The Captain said that in order to survive, lots should be`): print(`drawn, and 15 passengers should be picked at random to be`): print(`thrown into the sea, in order to ease the ship's load,`): print(`and enable the remaining passenger's to survive.`): print(`The Rabbi replied to the Captain that it was a good idea`): print(`and suggested a pseudo-random protocol for drowning,`): print(`a-la Josephus: eliminate every 9th (when they are placed`): print(`in a circle). This puzzle is mentioned in p. 214`): print(`of the Hebrew Encyclopedia's `): print(`enrty on "Even Ezra, Rabbi Abraham". It first appeared`): print(`in Rabbi Moshe Kimkhi's ``Mahalakh Shvilei HaDa'at''`): print(`(c. 1200 C.E. )`): lprint(``): print(`Written by Doron Zeilberger, `): print(`Temple University ,zeilberg@math.temple.edu.`): print(`Please report bugs to zeilberg@math.temple.edu`): print(`First Written: 28 Elul , 5757 `): print(`Version of Sept. 30, 1997`): print(`written by Doron Zeilberger(zeilberg@math.temple.edu).`): print(`" by Doron Zeilberger`): print(`The most current version of the package`): print(` is available from`): print(`http://www.math.temple.edu/~zeilberg`): print(`For a list of the procedures type ezra(), for help with`): print(`a specific procedure, type ezra(procedure_name)`): print(``): ezra:=proc() if args=NULL then print(`BenEzra: A small Maple package for solving`): print(`the (obvious generalization of the)`): print(`Ben-Ezra riddle: Rabbi Abraham Ben (Ibn) Ezra`): print(`was at sea, when a storm started to rage. `): print(`There were 15 good guys (Ben Ezra's disciples) `): print(` and 15 bad guys (empty-minded and naughty (rekim vepokhazim))`): print(`The Captain said that in order to survive, lots should be`): print(`drawn, and 15 passengers should be picked at random to be`): print(`thrown into the sea, in order to ease the ship's load,`): print(`and enable the remaining passenger's to survive.`): print(`The Rabbi replied to the Captain that it was a good idea`): print(`and suggested a pseudo-random protocol for drowning,`): print(`a-la Josephus: eliminate every 9th (when they are placed`): print(`in a circle). This puzzle is mentioned in p. 214`): print(`of the Hebrew Encyclopedia's `): print(`enrty on "Even Ezra, Rabbi Abraham". It first appeared`): print(`in Rabbi Moshe Kimkhi's ``Mahalakh Shvilei HaDa'at''`): print(`(c. 1200)`): lprint(``): print(`Written by Doron Zeilberger, `): print(`Temple University ,zeilberg@math.temple.edu.`): print(`Please report bugs to zeilberg@math.temple.edu`): print(`Contains the following procedures:`): print(` benezra, RABA `): fi: if nops([args])=1 and op(1,[args])=`benezra` then print(`benezra(r,GoodGuys,BadGuys):`): print(`Same as Raba, but instead to the number of good and`): print(`and bad guys, it inputs lists of them`): fi: if nops([args])=1 and op(1,[args])=`RABA` then print(`RABA(r,G,B): How to place G good guys (denoted by 1)`): print(` and B bad guys (denoted by 0) in a line (thought-of as`): print(` a circle, such that if, starting counting (1) at the first, `): print(`one throws to the sea the r^(th), and continues until B`): print(`guys are thrown to see, such that at the end all the`): print(`bad guys are drownded, and hence all the good guys survive`): print(``): print(`For example, to solve the original problem, type`): print(` RABA(9,15,15) `): fi: end: T:=proc(resh,m,r) local n, pl: n:=nops(resh): pl:=(m-1)+r-1 mod n +1: [op(1..pl-1,resh),op(pl+1..nops(resh),resh)],pl,r,op(pl,resh): end: S:=proc(resh1,pl,r,kha) local n, m: n:=nops(resh1)+1: m:=((pl-1)-(r-2) ) mod n : if m=0 then m:=n: fi: [op(1..pl-1,resh1),kha,op(pl..nops(resh1),resh1)],m,r: end: benezra:=proc(r,resh,reshNew) local i,resh1,kha,pl: resh1:=resh: pl:=1: for i from 1 to nops(reshNew) do kha:=op(i,reshNew): resh1:=S(resh1,pl,r,kha): pl:=resh1[2]: resh1:=resh1[1]: od: [op(pl..nops(resh1),resh1), op(1..pl-1,resh1)]: end: RABA:=proc(r,G,B) local i,resh,reshNew: resh:=[seq(1,i=1..G)]: reshNew:=[seq(0,i=1..B)]: benezra(r, resh,reshNew): end: