MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Using Mathematica to solve Smullyan "Scheherazade" puzzle?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72281] Using Mathematica to solve Smullyan "Scheherazade" puzzle?
  • From: "Kelly Jones" <kelly.terry.jones at gmail.com>
  • Date: Mon, 18 Dec 2006 06:55:43 -0500 (EST)

Can Mathematica be used to solve this puzzle from Raymond Smullyan's
"The Riddle of Scheherazade"? (isbn://0156006065/page/74)

Smullyan defines the following function. It's really a string-based
function, not a numerical one, even though it only uses the characters 0-9.

In the below, x refers to any string of digits, and "xy" on the left
side means the concatenation of the strings x and y, not
multiplication. Not all functions are in proper Mathematica form.

f["1x2"] = x;

(* eg: f["13542"] = "354" *)

f["3x"] = StringJoin[f[x], f[x]];

(* eg: f["315432"] = StringJoin[f["15432"], f["15432"]] =
StringJoin["543", "543"] = "543543" *)

f["4x"] = StringReverse[f[x]];

(* eg: f["4172962"] = StringReverse[f["172962"]] =
StringReverse["7296"] = "6927" *)

f["5x"] = If[StringLength[f[x]]>1, StringDrop[f[x],1], f[x]]]

(* eg: f["513472"] =
   If[StringLength[f["13472"]]>1, StringDrop[f["13472"],1], f["13472"]]] =
   If[StringLength["347"]>1, StringDrop["347",1], "347"] =
   If[True, "47", "347"] = "47"
*)

f["6x"] = StringJoin["1", f[x]]

(* eg: f["615832"] = StringJoin["1", f["15832"]] = StringJoin["1", "583"] =
   "1583"
*)

f["7x"] = StringJoin["2", f[x]]

(* eg: f["715832"] = StringJoin["2", f["15832"]] = StringJoin["2", "583"] =
   "2583"
*)

The rules are, of course, "recursive". Example:

f["33x"] = f["3x"]f["3x"] = f[x]f[x]f[x]f[x]

The function isn't necessarily defined for every string.

Smullyan now asks us to find values such that:

f[x] == x;
f[x] == StringJoin[x,x];
f[x] == StringReverse[x]; (* StringLength[x] <= 12 if possible *)
f[x] == StringDrop[x, -1];
f[f[x]] == x && f[x] != x;
f[f[x]] == StringReverse[x];

f[f[x]] == StringJoin[StringTake[x,-1], StringTake[x,{2,-2}], StringTake[x,1]]
(* right side is x with first and last digits reversed *)

StringTake[f[StringReverse[f[x]]], StringLength[f[StringReverse[f[x]]]]/2] ==
 StringTake[f[StringReverse[f[x]]], -StringLength[f[StringReverse[f[x]]]]/2]
&&
f[StringTake[f[StringReverse[f[x]]], StringLength[f[StringReverse[f[x]]]]/2] ==
x;

(* in other words, f[StringReverse[f[x]]] is of the form "zz", and f["z"] == x)

Of course, the answers are in the back of the book, so my general
question is: can Mathematica be used to solve puzzles of this sort?

Enumerating and testing all possible strings seems tedious (especially
given the length of some of the answers). Is there a clever
shortcut/methodology here?

-- 
We're just a Bunch Of Regular Guys, a collective group that's trying
to understand and assimilate technology. We feel that resistance to
new ideas and technology is unwise and ultimately futile.


  • Prev by Date: Re: system of nonlinear equations in mathematica?
  • Next by Date: Re: Re: A problem in mathematical logic
  • Previous by thread: Aspect Ratio -> 1 and copy-and-paste of figures
  • Next by thread: Re: Using Mathematica to solve Smullyan "Scheherazade" puzzle?