home *** CD-ROM | disk | FTP | other *** search
/ ftp.pasteur.org/FAQ/ / ftp-pasteur-org-FAQ.zip / FAQ / puzzles / archive / logic / part1 next >
Encoding:
Internet Message Format  |  1996-04-27  |  51.1 KB

  1. Received: from MIT.EDU (SOUTH-STATION-ANNEX.MIT.EDU [18.72.1.2]) by bloom-picayune.MIT.EDU (8.6.13/2.3JIK) with SMTP id AAA22841; Sat, 27 Apr 1996 00:40:26 -0400
  2. Received: from [199.164.164.1] by MIT.EDU with SMTP
  3.     id AA14101; Sat, 27 Apr 96 00:38:23 EDT
  4. Received: by questrel.questrel.com (940816.SGI.8.6.9/940406.SGI)
  5.     for news-answers-request@mit.edu id VAA20259; Fri, 26 Apr 1996 21:39:29 -0700
  6. Date: Fri, 26 Apr 1996 21:39:29 -0700
  7. X-Mail-Submission-From: chris@questrel.questrel.com (Chris Cole)
  8. Message-Id: <199604270439.VAA20259@questrel.questrel.com>
  9. To: news-answers-request@MIT.EDU
  10. Reply-To: chris@questrel.questrel.com
  11. Newsgroups: rec.puzzles,news.answers,rec.answers
  12. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!gatech!europa.eng.gtefsd.com!uunet!questrel!chris
  13. From: chris@questrel.com (Chris Cole)
  14. Subject: rec.puzzles Archive (logic), part 22 of 35
  15. Message-ID: <puzzles/archive/logic/part1_745653851@questrel.com>
  16. Followup-To: rec.puzzles
  17. Summary: This is part of an archive of questions
  18.  and answers that may be of interest to
  19.  puzzle enthusiasts.
  20.  Part 1 contains the index to the archive.
  21.  Read the rec.puzzles FAQ for more information.
  22. Sender: chris@questrel.com (Chris Cole)
  23. Reply-To: archive-comment@questrel.com
  24. Organization: Questrel, Inc.
  25. References: <puzzles/archive/Instructions_745653851@questrel.com>
  26. Date: Wed, 18 Aug 1993 06:06:09 GMT
  27. Approved: news-answers-request@MIT.Edu
  28. Expires: Thu, 1 Sep 1994 06:04:11 GMT
  29. Lines: 1393
  30. Xref: senator-bedfellow.mit.edu rec.puzzles:25006 news.answers:11526 rec.answers:1926
  31.  
  32. Archive-name: puzzles/archive/logic/part1
  33. Last-modified: 17 Aug 1993
  34. Version: 4
  35.  
  36.  
  37. ==> logic/29.p <==
  38. Three people check into a hotel.  They pay $30 to the manager and go
  39. to their room.  The manager finds out that the room rate is $25 and
  40. gives $5 to the bellboy to return.  On the way to the room the bellboy
  41. reasons that $5 would be difficult to share among three people so
  42. he pockets $2 and gives $1 to each person.
  43.  
  44. Now each person paid $10 and got back $1.  So they paid $9 each,
  45. totalling $27.  The bellboy has $2, totalling $29.
  46.  
  47. Where is the remaining dollar?
  48.  
  49. ==> logic/29.s <==
  50. Each person paid $9, totalling $27.  The manager has $25 and the bellboy $2.
  51. The bellboy's $2 should be added to the manager's $25 or subtracted from
  52. the tenants' $27, not added to the tenants' $27.
  53.  
  54. ==> logic/ages.p <==
  55. 1) Ten years from now Tim will be twice as old as Jane was when Mary was 
  56.    nine times as old as Tim.
  57.  
  58. 2) Eight years ago, Mary was half as old as Jane will be when Jane is one year
  59.    older than Tim will be at the time when Mary will be five times as old as 
  60.    Tim will be two years from now.
  61.  
  62. 3) When Tim was one year old, Mary was three years older than Tim will be when 
  63.    Jane is three times as old as Mary was six years before the time when Jane 
  64.    was half as old as Tim will be when Mary will be ten years older than Mary 
  65.    was when Jane was one-third as old as Tim will be when Mary will be three 
  66.    times as old as she was when Jane was born.
  67.  
  68.                              HOW OLD ARE THEY NOW?
  69.  
  70. ==> logic/ages.s <==
  71. The solution: Tim is 3, Jane is 8, and Mary is 15.  A little grumbling
  72. is in order here, as clue number 1 leads to the situation a year and a
  73. half ago, when Tim was 1 1/2, Jane was 6 1/2, and Mary was 13 1/2.
  74.  
  75. This sort of problem is easy if you write down a set of equations.  Let
  76. t be the year that Tim was born, j be the year that Jane was born, m be
  77. the year that Mary was born, and y be the current year.  As indefinite
  78. years come up, let y1, y2, ... be the indefinite years.  Then the
  79. equations are
  80.  
  81.  
  82. y + 10 - t = 2 (y1 - j)
  83. y1 - m = 9 (y1 - t)
  84.  
  85. y - 8 - m = 1/2 (y2 - j)
  86. y2 - j = 1 + y3 - t
  87. y3 - m = 5 (y + 2 - t)
  88.  
  89. t + 1 - m = 3 + y4 - t
  90. y4 - j = 3 (y5 - 6 - m)
  91. y5 - j = 1/2 (y6 - t)
  92. y6 - m = 10 + y7 - m
  93. y7 - j = 1/3 (y8 - t)
  94. y8 - m = 3 (j - m)
  95.  
  96. t = y - 3
  97. j = y - 8
  98. m = y - 15
  99.  
  100. ==> logic/attribute.p <==
  101. All the items in the first list share a particular attribute.  The second
  102. list is of some items lacking the attribute.
  103.  
  104. Set#1
  105.     with:  battery, key, yeast, bookmark
  106.     w/out: stapler, match, Rubik's cube, pill bottle
  107.  
  108. Set#2
  109.     with:  Rubik's cube, chess set, electrical wiring, compass needle
  110.     w/out: clock, rope, tic-tac-toe, pencil sharpener
  111.  
  112. Set#3:
  113.     with:  koosh, small intestine, Yorkshire Terrier, Christmas Tree
  114.     w/out: toothbrush, oak chair, soccer ball, icicle
  115.  
  116. Points to realize:
  117. 1.
  118.  There may be exceptions to any item on the list, for instance a particular
  119.  clock may share the properties of the 'with' list of problem two, BUT MOST
  120.  ORDINARY clocks do not.  All the properties apply the vast majority of the
  121.  the items mentioned.  Extraordinary exceptions should be ignored.
  122.  
  123. 2.
  124.  Pay the most attention to the 'with' list.  The 'without' list is only
  125.  present to eliminate various 'stupid' answers.
  126.  
  127. ==> logic/attribute.s <==
  128. The attribute puzzle format is a traditional format in math education.
  129. It occurs in logic materials developed in the sixties by EDC in Boston,
  130. with visual objects. Example:
  131.  
  132. these are gloops: A B C D E 
  133. these are not gloops: F G J L N
  134. which of these are gloops? O P Q R S
  135.  
  136. Set#1
  137.     with:  battery, key, yeast, bookmark
  138.     w/out: stapler, match, Rubik's cube, pill bottle
  139.  
  140. Needs to be placed inside something else when used for its usual purpose.
  141.  
  142. Set#2
  143.     with:  Rubik's cube, chess set, electrical wiring, compass needle
  144.     w/out: clock, rope, tic-tac-toe, pencil sharpener
  145.  
  146. Uses color to distinguish between otherwise identical parts.
  147.  
  148. Set#3:
  149.     with:  koosh, small intestine, Yorkshire Terrier, Christmas Tree
  150.     w/out: toothbrush, oak chair, soccer ball, icicle
  151.  
  152. Villiform.
  153.  
  154. ==> logic/bookworm.p <==
  155. A bookworm eats from the first page of an encyclopedia to the last
  156. page.  The bookworm eats in a straight line.  The encyclopedia consists
  157. of ten 1000-page volumes and is sitting on a bookshelf in the usual
  158. order.  Not counting covers, title pages, etc., how many pages does the
  159. bookworm eat through?
  160.  
  161. ==> logic/bookworm.s <==
  162. On a book shelf the first page of the first volume is on the "inside"
  163.   __                             __
  164. B|  |                           |  |F
  165. A|1 |...........................|10|R
  166. C|  |                           |  |O
  167. K|  |                           |  |N
  168.  |  |                           |  |T
  169.   ----------------------------------
  170. so the bookworm eats only through the cover of the first volume, then 8 times
  171. 1000 pages of Volumes 2 - 9, then through the cover to the 1st page of Vol 10.
  172. He eats 8,000 pages.
  173.  
  174. If the bookworm ate the first page and the last page, it ate 8,004 pages.
  175.  
  176. ==> logic/boxes.p <==
  177. Which Box Contains the Gold?
  178.  
  179. Two boxes are labeled "A" and "B".  A sign on box A says "The sign
  180. on box B is true and the gold is in box A".  A sign on box B says
  181. "The sign on box A is false and the gold is in box A".  Assuming there
  182. is gold in one of the boxes, which box contains the gold?
  183.  
  184. ==> logic/boxes.s <==
  185. The problem cannot be solved with the information given.
  186.  
  187. The sign on box A says "The sign on box B is true and the gold is in box A".
  188. The sign on box B says "The sign on box A is false and the gold is in box A".
  189. The following argument can be made: If the statement on box A is true, then
  190. the statement on box B is true, since that is what the statement on box A
  191. says.  But the statement on box B states that the statement on box A is false,
  192. which contradicts the original assumption.  Therefore, the statement on box A
  193. must be false.  This implies that either the statement on box B is false or
  194. that the gold is in box B.  If the statement on box B is false, then either
  195. the statement on box A is true (which it cannot be) or the gold is in box B.
  196. Either way, the gold is in box B.
  197.  
  198. However, there is a hidden assumption in this argument: namely, that
  199. each statement must be either true or false.  This assumption leads to
  200. paradoxes, for example, consider the statement: "This statement is
  201. false."  If it is true, it is false; if it is false, it is true.  The
  202. only way out of the paradox is to deny that the statement is either true
  203. or false and label it meaningless instead.  Both of the statements on the
  204. boxes are therefore meaningless and nothing can be concluded from them.
  205.  
  206. In general, statements about the truth of other statements lead to
  207. contradictions.  Tarski invented metalanguages to avoid this problem.
  208. To avoid paradox, a statement about the truth of a statement in a language
  209. must be made in the metalanguage of the language.
  210.  
  211. Common sense dictates that this problem cannot be solved with the information
  212. given.  After all, how can we deduce which box contains the gold simply by
  213. reading statements written on the outside of the box?  Suppose we deduce that
  214. the gold is in box B by whatever line of reasoning we choose.  What is to stop
  215. us from simply putting the gold in box A, regardless of what we deduced?
  216. (cf. Smullyan, "What Is the Name of This Book?", Prentice-Hall, 1978,    #70)
  217.  
  218. ==> logic/camel.p <==
  219. An Arab sheikh tells his two sons to race their camels to a distant
  220. city to see who will inherit his fortune.  The one whose camel is
  221. slower will win.  The brothers, after wandering aimlessly for days, ask
  222. a wise man for advise.  After hearing the advice they jump on the
  223. camels and race as fast as they can to the city.  What does the wise
  224. man say?
  225.  
  226. ==> logic/camel.s <==
  227. The wiseman tells them to switch camels.
  228.  
  229. ==> logic/centrifuge.p <==
  230. You are a biochemist, working with a 12-slot centrifuge.  This is a gadget
  231. that has 12 equally spaced slots around a central axis, in which you can
  232. place chemical samples you want centrifuged.  When the machine is turned on,
  233. the samples whirl around the central axis and do their thing.
  234.  
  235. To ensure that the samples are evenly mixed, they must be distributed in the
  236. 12 slots such that the centrifuge is balanced evenly.  For example, if you
  237. wanted to mix 4 samples, you could place them in slots 12, 3, 6 and 9
  238. (assuming the slots are numbered from 1 to 12 like a clock).
  239.  
  240. Problem:  Can you use the centrifuge to mix 5 samples?
  241.  
  242. ==> logic/centrifuge.s <==
  243. The superposition of any two solutions is yet another solution, so given
  244. that the factors > 1 of 12 (2, 3, 4, 6, 12) are all solutions, the
  245. only thing to check about, for example, the proposed solution 2+3 is
  246. that not all ways of combining 2 & 3 would have centrifuge tubes
  247. from one subsolution occupying the slot for one of the tubes in
  248. another solution.  For the case 2+3, there is no problem:  Place 3
  249. tubes, one in every 4th position, then place the 4th and 5th
  250. diametrically opposed (each will end up in a slot adjacent to one of
  251. the first 3 tubes).  The obvious generalization is, what are the
  252. numbers of tubes that cannot be balanced?  Observing that there are
  253. solutions for 2,3,4,5,6 tubes and that if X has a solution, 12-X has
  254. also one (obtained by swapping tubes and holes), it is obvious that
  255. 1 and 11 are the only cases without solutions.
  256.  
  257. Here is how this problem is often solved in practice:  A dummy tube
  258. is added to produce a total number of tubes that is easy to balance.
  259. For example, if you had to centrifuge just one sample, you'd add a
  260. second tube opposite it for balance.
  261.  
  262. ==> logic/chain.p <==
  263. What is the least number of links you can cut in a chain of 21 links to be able
  264. to give someone all possible number of links up to 21?
  265.  
  266. ==> logic/chain.s <==
  267. Two.
  268.  
  269.     OOO C OOOOO C OOOOOOOOOOO
  270. (where Os are chained unbroken links, and the Cs are the unchained broken links)
  271.  
  272. And equivalently:
  273.  
  274.     OOO C OOOOOO C OOOOOOOOOO
  275.  
  276. ==> logic/children.p <==
  277. A man walks into a bar, orders a drink, and starts chatting with the
  278. bartender.  After a while, he learns that the bartender has three
  279. children.  "How old are your children?" he asks.  "Well," replies the
  280. bartender, "the product of their ages is 72."  The man thinks for a
  281. moment and then says, "that's not enough information."  "All right,"
  282. continues the bartender, "if you go outside and look at the building
  283. number posted over the door to the bar, you'll see the sum of the
  284. ages."  The man steps outside, and after a few moments he reenters and
  285. declares, "Still not enough!"  The bartender smiles and says, "My
  286. youngest just loves strawberry ice cream."
  287.  
  288. How old are the children?
  289.  
  290. A variant of the problem is for the sum of the ages to be 13 and the
  291. product of the ages to be the number posted over the door.  In this
  292. case, it is the oldest that loves ice cream.
  293.  
  294. Then how old are they?
  295.  
  296.  
  297. ==> logic/children.s <==
  298. First, determine all the ways that three ages can multiply together to get 72:
  299.  
  300. 72  1  1        (quite a feat for the bartender)
  301. 36  2  1
  302. 24  3  1
  303. 18  4  1
  304. 18  2  2
  305. 12  6  1
  306. 12  3  2
  307. 9  4  2
  308. 9  8  1
  309. 8  3  3
  310. 6  6  2
  311. 6  4  3
  312.  
  313. As the man says, that's not enough information; there are many possibilities.
  314. So the bartender tells him where to find the sum of the ages--the man now knows
  315. the sum even though we don't.  Yet he still insists that there isn't enough
  316. info.  This must mean that there are two permutations with the same sum;
  317. otherwise the man could have easily deduced the ages.
  318.  
  319. The only pair of permutations with the same sum are 8 3 3 and 6 6 2, which both
  320. add up to 14 (the bar's address).  Now the bartender mentions his
  321. "youngest"--telling us that there is one child who is younger than the other
  322. two.  This is impossible with 8 3 3--there are two 3 year olds.  Therefore the
  323. ages of the children are 6, 6, and 2.
  324.  
  325. Pedants have objected that the problem is insoluble because there could be
  326. a youngest between two three year olds (even twins are not born exactly at
  327. the same time).  However, the word "age" is frequently used to denote the
  328. number of years since birth.  For example, I am the same age as my wife,
  329. even though technically she is a few months older than I am.  And using the
  330. word "youngest" to mean "of lesser age" is also in keeping with common parlance.
  331. So I think the solution is fine as stated.
  332.  
  333. In the sum-13 variant, the possibilities are:
  334.  
  335. 11  1  1
  336. 10  2  1
  337. 9  3  1
  338. 9  2  2
  339. 8  4  1
  340. 8  3  2
  341. 7  5  1
  342. 7  4  2
  343. 7  3  3
  344. 6  6  1
  345. 6  5  2
  346. 6  4  3
  347.  
  348. The two that remain are 9 2 2 and 6 6 1 (both products equal 36).  The
  349. final bit of info (oldest child) indicates that there is only one
  350. child with the highest age.  This cancels out the 6 6 1 combination, leaving
  351. the childern with ages of 9, 2, and 2.
  352.  
  353. ==> logic/condoms.p <==
  354. How can a man have mutually safe sex with three women with only two condoms?
  355. How can three men have mutually safe sex with one woman with two condoms?
  356.  
  357. ==> logic/condoms.s <==
  358. Use both condoms on the first woman.  Take off the outer condom (turning it
  359. inside-out in the process) and set it aside.  Use the inner condom alone on
  360. the second woman.  Put the outer condom back on.  Use it on the third woman.
  361.  
  362. First man uses both condoms.  Take off the outer condom (do NOT reverse
  363. it) and have second man use it.  First man takes off the inner condom
  364. (turning it inside-out).  Third man puts on this condom, followed by
  365. second man's condom.
  366.  
  367. ==> logic/dell.p <==
  368. How can I solve logic puzzles (e.g., as published by Dell) automatically?
  369.  
  370. ==> logic/dell.s <==
  371. #include    <setjmp.h>
  372.  
  373. #define    EITHER        if (S[1] = S[0], ! setjmp((S++)->jb)) {
  374. #define    OR        } else EITHER
  375. #define    REJECT        longjmp((--S)->jb, 1)
  376. #define    END_EITHER    } else REJECT;
  377.  
  378. /* values in tmat: */
  379. #define    T_UNK    0
  380. #define    T_YES    1
  381. #define    T_NO    2
  382.  
  383. #define    Val(t1,t2)    (S->tmat[t1][t2])
  384. #define    CLASS(x)        \
  385.         (((x) / NUM_ITEM) * NUM_ITEM)
  386. #define    EVERY_TOKEN(x)        \
  387.         (x = 0; x < TOT_TOKEN; x++)
  388. #define    EVERY_ITEM(x, class)    \
  389.         (x = CLASS(class); x < CLASS(class) + NUM_ITEM; x++)
  390.  
  391. #define    BEGIN                        \
  392. struct state {                        \
  393.     char    tmat[TOT_TOKEN][TOT_TOKEN];        \
  394.     jmp_buf jb;                    \
  395. } States[100], *S = States;                \
  396.                             \
  397. main()                            \
  398. {                            \
  399.     int    token;                    \
  400.                             \
  401.     for EVERY_TOKEN(token)                \
  402.         yes(token, token);            \
  403.     EITHER
  404.  
  405. /* Here is the problem-specific data */
  406. #define    NUM_ITEM    5
  407. #define    NUM_CLASS    6
  408. #define    TOT_TOKEN    (NUM_ITEM * NUM_CLASS)
  409.  
  410. #define    HOUSE_0        0
  411. #define    HOUSE_1        1
  412. #define    HOUSE_2        2
  413. #define    HOUSE_3        3
  414. #define    HOUSE_4        4
  415.  
  416. #define    ENGLISH        5
  417. #define    SPANISH        6
  418. #define    NORWEG        7
  419. #define    UKRAIN        8
  420. #define    JAPAN        9
  421.  
  422. #define    GREEN        10
  423. #define    RED        11
  424. #define    IVORY        12
  425. #define    YELLOW        13
  426. #define    BLUE        14
  427.  
  428. #define    COFFEE        15
  429. #define    TEA        16
  430. #define    MILK        17
  431. #define    OJUICE        18
  432. #define    WATER        19
  433.  
  434. #define    DOG        20
  435. #define    SNAIL        21
  436. #define    FOX        22
  437. #define    HORSE        23
  438. #define    ZEBRA        24
  439.  
  440. #define    OGOLD        25
  441. #define    PLAYER        26
  442. #define    CHESTER        27
  443. #define    LSTRIKE        28
  444. #define    PARLIA        29
  445.  
  446. char *names[] = {
  447.     "HOUSE_0", "HOUSE_1", "HOUSE_2", "HOUSE_3", "HOUSE_4",
  448.     "ENGLISH", "SPANISH", "NORWEG", "UKRAIN", "JAPAN",
  449.     "GREEN", "RED", "IVORY", "YELLOW", "BLUE",
  450.     "COFFEE", "TEA", "MILK", "OJUICE", "WATER",
  451.     "DOG", "SNAIL", "FOX", "HORSE", "ZEBRA",
  452.     "OGOLD", "PLAYER", "CHESTER", "LSTRIKE", "PARLIA",
  453. };
  454.  
  455.     BEGIN
  456.  
  457.     yes(ENGLISH, RED);    /* Clue 1 */
  458.     yes(SPANISH, DOG);    /* Clue 2 */
  459.     yes(COFFEE, GREEN);    /* Clue 3 */
  460.     yes(UKRAIN, TEA);    /* Clue 4 */
  461.  
  462.     EITHER            /* Clue 5 */
  463.         yes(IVORY, HOUSE_0);
  464.         yes(GREEN, HOUSE_1);
  465.     OR
  466.         yes(IVORY, HOUSE_1);
  467.         yes(GREEN, HOUSE_2);
  468.     OR
  469.         yes(IVORY, HOUSE_2);
  470.         yes(GREEN, HOUSE_3);
  471.     OR
  472.         yes(IVORY, HOUSE_3);
  473.         yes(GREEN, HOUSE_4);
  474.     END_EITHER
  475.  
  476.     yes(OGOLD, SNAIL);    /* Clue 6 */
  477.     yes(PLAYER, YELLOW);    /* Clue 7 */
  478.     yes(MILK, HOUSE_2);    /* Clue 8 */
  479.     yes(NORWEG, HOUSE_0);    /* Clue 9 */
  480.  
  481.     EITHER            /* Clue 10 */
  482.         yes(CHESTER, HOUSE_0);
  483.         yes(FOX, HOUSE_1);
  484.     OR
  485.         yes(CHESTER, HOUSE_4);
  486.         yes(FOX, HOUSE_3);
  487.     OR
  488.         yes(CHESTER, HOUSE_1);
  489.         EITHER    yes(FOX, HOUSE_0);
  490.         OR    yes(FOX, HOUSE_2);
  491.         END_EITHER
  492.     OR
  493.         yes(CHESTER, HOUSE_2);
  494.         EITHER    yes(FOX, HOUSE_1);
  495.         OR    yes(FOX, HOUSE_3);
  496.         END_EITHER
  497.     OR
  498.         yes(CHESTER, HOUSE_3);
  499.         EITHER    yes(FOX, HOUSE_2);
  500.         OR    yes(FOX, HOUSE_4);
  501.         END_EITHER
  502.     END_EITHER
  503.  
  504.     EITHER            /* Clue 11 */
  505.         yes(PLAYER, HOUSE_0);
  506.         yes(HORSE, HOUSE_1);
  507.     OR
  508.         yes(PLAYER, HOUSE_4);
  509.         yes(HORSE, HOUSE_3);
  510.     OR
  511.         yes(PLAYER, HOUSE_1);
  512.         EITHER    yes(HORSE, HOUSE_0);
  513.         OR    yes(HORSE, HOUSE_2);
  514.         END_EITHER
  515.     OR
  516.         yes(PLAYER, HOUSE_2);
  517.         EITHER    yes(HORSE, HOUSE_1);
  518.         OR    yes(HORSE, HOUSE_3);
  519.         END_EITHER
  520.     OR
  521.         yes(PLAYER, HOUSE_3);
  522.         EITHER    yes(HORSE, HOUSE_2);
  523.         OR    yes(HORSE, HOUSE_4);
  524.         END_EITHER
  525.     END_EITHER
  526.  
  527.     yes(LSTRIKE, OJUICE);    /* Clue 12 */
  528.     yes(JAPAN, PARLIA);    /* Clue 13 */
  529.  
  530.     EITHER            /* Clue 14 */
  531.         yes(NORWEG, HOUSE_0);
  532.         yes(BLUE, HOUSE_1);
  533.     OR
  534.         yes(NORWEG, HOUSE_4);
  535.         yes(BLUE, HOUSE_3);
  536.     OR
  537.         yes(NORWEG, HOUSE_1);
  538.         EITHER    yes(BLUE, HOUSE_0);
  539.         OR    yes(BLUE, HOUSE_2);
  540.         END_EITHER
  541.     OR
  542.         yes(NORWEG, HOUSE_2);
  543.         EITHER    yes(BLUE, HOUSE_1);
  544.         OR    yes(BLUE, HOUSE_3);
  545.         END_EITHER
  546.     OR
  547.         yes(NORWEG, HOUSE_3);
  548.         EITHER    yes(BLUE, HOUSE_2);
  549.         OR    yes(BLUE, HOUSE_4);
  550.         END_EITHER
  551.     END_EITHER
  552.  
  553. /* End of problem-specific data */
  554.  
  555.         solveit();
  556.     OR
  557.         printf("All solutions found\n");
  558.         exit(0);
  559.     END_EITHER
  560. }
  561.  
  562. no(a1, a2)
  563. {
  564.     int    non1, non2, token;
  565.  
  566.     if (Val(a1, a2) == T_YES)
  567.         REJECT;
  568.     else if (Val(a1, a2) == T_UNK) {
  569.         Val(a1, a2) = T_NO;
  570.         no(a2, a1);
  571.         non1 = non2 = -1;
  572.  
  573.         for EVERY_ITEM(token, a1)
  574.             if (Val(token, a2) != T_NO)
  575.                 if (non1 == -1)
  576.                     non1 = token;
  577.                 else
  578.                     break;
  579.         if (non1 == -1)
  580.             REJECT;
  581.         else if (token == CLASS(a1) + NUM_ITEM)
  582.             yes(non1, a2);
  583.  
  584.         for EVERY_TOKEN(token)
  585.             if (Val(token, a1) == T_YES)
  586.                 no(a2, token);
  587.     }
  588. }
  589.  
  590. yes(a1, a2)
  591. {
  592.     int    token;
  593.  
  594.     if (Val(a1, a2) == T_NO)
  595.         REJECT;
  596.     else if (Val(a1, a2) == T_UNK) {
  597.         Val(a1, a2) = T_YES;
  598.         yes(a2, a1);
  599.         for EVERY_ITEM(token, a1)
  600.             if (token != a1)
  601.                 no(token, a2);
  602.         for EVERY_TOKEN(token)
  603.             if (Val(token, a1) == T_YES)
  604.                 yes(a2, token);
  605.             else if (Val(token, a1) == T_NO)
  606.                 no(a2, token);
  607.     }
  608. }
  609.  
  610. solveit()
  611. {
  612.     int    token, tok2;
  613.  
  614.     for EVERY_TOKEN(token)
  615.         for (tok2 = token; tok2 < TOT_TOKEN; tok2++)
  616.             if (Val(token, tok2) == T_UNK) {
  617.                 EITHER
  618.                     yes(token, tok2);
  619.                 OR
  620.                     no(token, tok2);
  621.                 END_EITHER;
  622.                 return solveit();
  623.             }
  624.     printf("Solution:\n");
  625.     for EVERY_ITEM(token, 0) {
  626.         for (tok2 = NUM_ITEM; tok2 < TOT_TOKEN; tok2++)
  627.             if (Val(token, tok2) == T_YES)
  628.                 printf("\t%s %s\n",names[token],names[tok2]);
  629.         printf("\n");
  630.     }
  631.     REJECT;
  632. }
  633.  
  634. ---
  635. james@crc.ricoh.com (James Allen)
  636.  
  637. ==> logic/elimination.p <==
  638. 97 baseball teams participate in an annual state tournament.
  639. The way the champion is chosen for this tournament is by the same old
  640. elimination schedule. That is, the 97 teams are to be divided into
  641. pairs, and the two teams of each pair play against each other.
  642. After a team is eliminated from each pair, the winners would
  643. be again divided into pairs, etc.  How many games must be played
  644. to determine a champion?
  645.  
  646. ==> logic/elimination.s <==
  647. In order to determine a winner all but one team must lose.
  648. Therefore there must be at least 96 games.
  649.  
  650. ==> logic/flip.p <==
  651. How can a toss be called over the phone (without requiring trust)?
  652.  
  653. ==> logic/flip.s <==
  654. A flips a coin.  If the result is heads, A multiplies 2 prime numbers
  655. containing about 90 digits; if the result is tails, A multiplies 3
  656. prime numbers containing about 60 digits.  A tells B the result of the
  657. multiplication.  B now calls either heads or tails and tells A.  A then
  658. supplies B with the original numbers to verify the flip.
  659.  
  660. Consider what is involved in multiplying 90 digit numbers.  Using the method
  661. of long multiplication that we all learned in grade school, you have maybe
  662. 90 or so strings of 90 characters (or "digits") each.  That's no problem for
  663. a computer to deal with.  The magnitude of the number represented isn't
  664. much of a factor; we're only manipulating the string of digits.
  665.  
  666. Consider what is involved in factoring 90 digit numbers.  There are of course,
  667. little tricks for determining factorability by small integers which we all
  668. learned in grade school.  (Is the last digit even?  Is the sum of all the
  669. digits divisible by 9?  And so on.)  But these are of little use in factoring
  670. large numbers with large factors.  In fact, there is no essentially better
  671. method than checking every number smaller that the number to be factored and
  672. seeing if it one divides the other evenly.  We means we could be checking some
  673. 100,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000
  674. nummbers.  This is very hard to do, even for a supercomputer.  Here, the
  675. number of digits this number has is of little consequence.  It is the
  676. magnitude of the number that we have to worry about, and there just isn't 
  677. enough time in the world to do this properly.
  678.  
  679. Where does A find a list of 60- and 90- digit prime numbers?  Well, that's not
  680. to hard to come by.  The simplest method to find a few prime numbers is simply
  681. to choose a 90-digit number (or 60-digit number, as the case warrants)
  682. randomly, and check to see if it is prime.  You won't have to wait too long
  683. before you stumble across a prime number.
  684.  
  685. "But wait!" you cry.  "I thought you just said it was incredibly difficult
  686. to factor large numbers.  If that's the case, then how are you going to know
  687. if the number you randomly choose is prime?"  A good question.  Here we enter
  688. into the strange an wacky world of number theory.  It turns out (and I won't
  689. explain how unless someone asks) there are "probabalistic" algorithms,
  690. which depend on us choosing numbers at random.  There are probablistic
  691. algorithms that when given a prime number, will quickly tell us that it is
  692. a prime number, and when given a composite number, will either tell us that
  693. it is a composite number (with very, very high probability) or will tell us
  694. that it is a prime number (with very, very low probability.)  What's the use
  695. of an algorithm that only returns the right answer "with very, very high
  696. probability?"  Well, we can make this probability as high as we want, just by
  697. running the algorithm longer.  In fact, it is within our technological
  698. abilities to quickly run this algorithm for 90-digit numbers so that the
  699. probability of it giving a wrong answer is less than the probability of a
  700. cosmic ray striking a vital part of the computer at some vital time and causing
  701. the computer to spit out the wrong answer anyway.  That's what I mean by "very,
  702. very high."
  703.  
  704. ==> logic/flowers.p <==
  705. How many flowers do I have if all of them are roses except two, all of
  706. them are tulips except two, and all of them are daisies except two?
  707.  
  708. ==> logic/flowers.s <==
  709. There are two solutions:
  710.  
  711. Three flowers: rose, tulip, daisy
  712. Two flowers:   carnation, geranium
  713.  
  714. ==> logic/friends.p <==
  715. Any group of 6 or more contains either 3 mutual friends or 3 mutual strangers.
  716. Prove it.
  717.  
  718. ==> logic/friends.s <==
  719. Take a person X.  Of the five other people, there must either be at least three
  720. acquaintances of X or at least three strangers of X.  Assume wlog that X has
  721. three strangers A,B,C.  Unless A,B,C is the required triad of acquaintances,
  722. they must include a pair of strangers, wlog A,B.  Then X,A,B is the required
  723. triad of strangers, QED.
  724.  
  725. ==> logic/hofstadter.p <==
  726. In first-order logic, find a predicate P(x) which means "x is a power of 10."
  727.  
  728. ==> logic/hofstadter.s <==
  729. Well, one summer, I decided to tackle the problem. Not having any great
  730. knowledge of number theory, I used a more brute force approach. Note
  731. that for greater comprehensibility, I have broken the resulting formula
  732. up into several stages, but it would not be difficult to put it
  733. back together into one vast formula:
  734.  
  735. {e is prime:}
  736. PRIME(e) := 
  737.    ~Eb:Ec:((b+2)*(c+2) = e)
  738.  
  739. {if e is a prime, true iff a is a power of e:}
  740. PPOWER(a,e) :=
  741.    Ab:Ac:((b*c = a) -> ((b = 1) or (Ed: (e*d) = b)))
  742.  
  743. {if e is a prime, and a is a power of e, true iff d is the
  744.  (log_e a)th digit (counting from the right, starting with 0)
  745.  in the base-e expansion of n:}
  746. DIG(a,e,d,n) :=
  747.    (d < e) & Eb:Ec:((c < a) & (n = (b*e*a) + (d*a) + c))
  748.  
  749. {if e is prime, and a is a power of e, true iff n has exactly
  750.  (log_e a) digits in its base-e expansion (0 is counted as having 0
  751.  digits:}
  752. LENGTH(e,a,n):=
  753.    (n < a) & Ab:((PPOWER(b,e) & (b < a)) -> (b <= n))
  754.  
  755. POWER_OF_TEN(x):=
  756.    Ee:(PRIME(e) & (e > x) &
  757.        En:Ea:(LENGTH(e,a,n) &
  758.               DIG(1,e,1,n) &
  759.               Ai:Aj:Au:(  (PPOWER(u,e) & ((e*u) < a)
  760.                & DIG(u,e,i,n) & DIG(e*u,e,j,n))
  761.                           -> j = (10 * i)  ) &
  762.               Eu:(PPOWER(u,e) & (e*u = a) & DIG(u,e,x,n))
  763.        )     )
  764.  
  765. The basic idea is that you are asserting that for some prime e greater
  766. than x, we can find a number n which, when expressed in base-e notation,
  767. will have 1 in its units place, 10 in its e's place, 100 in its (e^2)'s
  768. place, and in general have the "digit" in each place be 10 times
  769. greater than the one to its right, such that the leftmost digit is our x.
  770.  
  771. To translate into Hofstadter's notation, of course, we must use horse-shoes
  772. instead of ->'s, big carets instead of &'s, letters a through e (followed
  773. by however many ''s) exclusively, and so forth. (We must also replace <'s
  774. and <= with appropriate expansions, and substitute in for our capitalized
  775. formula abbreviations.) This is left as an exercise to the reader.
  776.  
  777. Kevin Wald
  778. wald2@husc.harvard.edu
  779.  
  780. ==> logic/hundred.p <==
  781. A sheet of paper has statements numbered from 1 to 100.  Statement n says
  782. "exactly n of the statements on this sheet are false."  Which statements are
  783. true and which are false?  What if we replace "exactly" by "at least"?
  784.  
  785. ==> logic/hundred.s <==
  786. From _Litton's Problematical Recreations_
  787.  
  788. It is tempting to argue as follows:
  789.  
  790. At most one statement can be true (they are mutually contradictory).
  791. If they are all false, statement 100 would be true, which is no good.
  792. So 99 are false, and statement 99 is true.
  793.  
  794. If replaced by "at least", and the "real" number of false statements is
  795. x, then statements x+1 to 100 will be false (since they falsely claim
  796. that there are more false statements than there actually are). So, 100-x are 
  797. false, ie.  x=100-x, so x=50. The first 50 statements are true, and statements
  798. 51 to 100 are false. 
  799.  
  800. However, there is a hidden and incorrect assumption in this argument.
  801. To see this, suppose that there is one statement on the sheet and it
  802. says "One statement is false"  or "At least one statement is false,"
  803. either way it implies "this statement is false," which is a familiar
  804. paradoxical statement.  We have learned that this paradox arises because
  805. of the false assumption that all statements are either true or false.
  806. This is the hidden assumption in the above reasoning.
  807.  
  808. If it is acknowledged that some of the statements on the page may be
  809. neither true nor false (i.e., meaningless), then nothing whatsoever can
  810. be concluded about which statements are true or false.
  811.  
  812. This problem has been carefully contrived to appear to be solvable (like
  813. the vacuous statement "this statement is true").  By changing the
  814. numbers in some statements and changing "true" to "false," various
  815. circular forms of the liar's paradox can be constructed.  A much
  816. more complicated version of the same problem is:
  817.  
  818.  1) At least one of the last two statements in this list is true.
  819.  
  820.  2) This is either the first true or the first false statement in the
  821.     list.
  822.  
  823.  3) There exist three consecutive false statements.
  824.  
  825.  4) The difference beween the numbers of the last true statement and
  826.     the first true statement is a factor of the unknown number.
  827.  
  828.  5) The sum of the numbers of the true statements is the unknown
  829.     number.
  830.  
  831.  6) This is not the last true statement.
  832.  
  833.  7) Each true statement's number is a factor of the unknown number.
  834.  
  835.  8) The unknown number equals the percentage of these statements which
  836.    are true.
  837.  
  838.  9) The number of different factors which the unknown number has
  839.    (excluding 1 and itself) is more than the sum of the numbers of the
  840.    true statements.
  841.  
  842. 10) There are no three cosecutive true statements.
  843.  
  844. What is the number?
  845.  
  846. The incorrect but plausible solution is:
  847.  
  848. By 2, either way 1 must be false, and then so must both 9 and 10.
  849.  
  850. 6, if false, says "This is the last true statement", which gives
  851. a paradox, thus 6 must be true, and so must 7 and/or 8.
  852.  
  853. 7 and 8 cannot both be true, as the number had to be a multiple
  854. of 6,7,8 , that is a multiple of 168 (by 7), and less than 100 (by 8)
  855.  
  856. If 8 is false, then 3 is true (8,9,10 is false), if 8 is true, then
  857. 3 is false (3 cannot be true when both 6 and 8 are true, then there
  858. are no three consecutive statements left).
  859.  
  860. So we have either
  861.  
  862. A) F X F X X T F T F F
  863. or
  864. B) F X T X X T T F F F
  865.  
  866. In A), 4 and 5 must be true (by false 10), and 2 may be true or false.
  867. So by 5 the number shall be either 27 (2+3+4+5+6+7) or 25 (3+4+5+6+7).
  868. None of these can fullfill 8, though, so A) is out leaving us with B)
  869.  
  870. Now, (by 7) 3,6 and 7 are factors, the number must be a multiple of
  871. 42, as 2+3+4+5+6+7=27, 5 must be false. 
  872.  
  873. By false 10, 2 and 4 must be true, that is 5 shall be a multiple
  874. of the number. Now the number must be a multiple of 2,3,4,5,6 and 7,
  875. that is a multiple of 3*4*5*7=420. 420 has 22 different factors
  876. (2,3,4,5,6,7,10,12,14,15,20,21,28,30,35,42,60,70,84,105,140,210)
  877. and the sum 2+3+4+6+7 = 22, so the only multiple of 420 that
  878. fulfills false 9 is 420.
  879.  
  880. ==> logic/inverter.p <==
  881. Can a digital logic circuit with two inverters invert N independent inputs?
  882. The circuit may contain any number of AND or OR gates.
  883.  
  884. ==> logic/inverter.s <==
  885. It can be shown that N inverters can invert 2^N-1 independent inputs,
  886. given an unlimited supply of AND and OR gates. The classic version of
  887. this puzzle is to invert 3 independent inputs using AND gates, OR
  888. gates, and only 2 inverters.
  889.  
  890. This is solved by:
  891.         n1 = not(i1 and i2 or i1 and i3 or i2 and i3);
  892.         n2 = not((i1 or i2 or i3) and n1  or  i1 and i2 and i3);
  893.         o1 = (i2 or i3 or n2) and n1  or  i2 and i3 and n2;
  894.         o2 = (i1 or i3 or n2) and n1  or  i1 and i3 and n2;
  895.         o3 = (i1 or i2 or n2) and n1  or  i1 and i2 and n2;
  896.  
  897. i1, i2, and i3 are the inputs, n1 and n2 are the inverted signals, and
  898. o1, o2, and o3 are the outputs.  "and" has higher precedence than "or".
  899.  
  900. So, start with N inverters.  Replace 3 of them with 2.
  901. Keep doing that until you're down to 2 inverters.
  902.  
  903. I was skeptical at first, because such a design requires so much feedback
  904. that I was sure the system would oscillate when switching between two
  905. particular states.  But after writing a program to test every possible state 
  906. change (32^2), it appears that this system settles after a maximum of
  907. 3 feedback logic iterations. I did not include gate delays in the simulation,
  908. however, which could increase the number of iterations before the system
  909. settles.
  910.  
  911. In any case, it appears that the world needs only 2 inverters! :-)
  912.  
  913. ==> logic/josephine.p <==
  914. The recent expedition to the lost city of Atlantis discovered scrolls
  915. attributted to the great poet, scholar, philosopher Josephine. They
  916. number eight in all, and here is the first.
  917.  
  918. THE KINGDOM OF MAMAJORCA, WAS RULED BY QUEEN HENRIETTA I. IN MAMAJORCA
  919. WOMEN HAVE TO PASS AN EXTENSIVE LOGIC EXAM BEFORE THEY ARE ALLOWED TO
  920. GET MARRIED. QUEENS DO NOT HAVE TO TAKE THIS EXAM. ALL THE WOMEN IN
  921. MAMAJORCA ARE LOYAL TO THEIR QUEEN AND DO WHATEVER SHE TELLS THEM TO.
  922. THE QUEENS OF MAMAJORCA ARE TRUTHFUL. ALL SHOTS FIRED IN MAMAJORCA CAN
  923. BE HEARD IN EVERY HOUSE. ALL ABOVE FACTS ARE KNOWN TO BE COMMON
  924. KNOWLEDGE.
  925.  
  926. HENRIETTA WAS WORRIED ABOUT THE INFIDELITY OF THE MARRIED MEN IN
  927. MAMAJORCA.  SHE SUMMONED ALL THE WIVES TO THE TOWN SQUARE, AND MADE
  928. THE FOLLOWING ANNOUNCEMENT. "THERE IS AT LEAST ONE UNFAITHFUL HUSBAND
  929. IN MAMAJORCA. ALL WIVES KNOW WHICH HUSBANDS ARE UNFAITHFUL, BUT HAVE
  930. NO KNOWLEDGE ABOUT THE FIDELITY OF THEIR OWN HUSBAND. YOU ARE
  931. FORBIDDEN TO DISCUSS YOUR HUSBAND'S FAITHFULNESS WITH ANY OTHER WOMAN.
  932. IF YOU DISCOVER THAT YOUR HUSBAND IS UNFAITHFUL, YOU MUST SHOOT HIM AT
  933. PRECISELY MIDNIGHT OF THE DAY YOU FIND THAT OUT."
  934.  
  935. THIRTY-NINE SILENT NIGHTS FOLLOWED THE QUEEN'S ANNOUNCEMENT. ON THE
  936. FORTIETH NIGHT, SHOTS WERE HEARD. QUEEN HENRIETTA I IS REVERED IN
  937. MAMAJORCAN HISTORY.
  938.  
  939. As with all philosophers Josephine doesn't provide the question, but leaves
  940. it implicit in his document. So figure out the questions - there are two -
  941. and answer them.
  942.  
  943. Here is Josephine's second scroll.
  944.  
  945. QUEEN HENRIETTA I WAS SUCCEEDED BY DAUGHTER QUEEN HENRIETTA II. AFTER
  946. A WHILE HENRIETTA LIKE HER FAMOUS MOTHER BECAME WORRIED ABOUT THE
  947. INFIDELITY PROBLEM. SHE DECIDED TO ACT, AND SENT A LETTER TO HER
  948. SUBJECTS (WIVES) THAT CONTAINED THE EXACT WORDS OF HENRIETTA I'S
  949. FAMOUS SPEECH.  SHE ADDED THAT THE LETTERS WERE GUARENTEED TO REACH
  950. ALL WIVES EVENTUALLY.
  951.  
  952. QUEEN HENRIETTA II IS REMEMBERED AS A FOOLISH AND UNJUST QUEEN.
  953.  
  954. What is the question and answer implied by this scroll?
  955.  
  956. ==> logic/josephine.s <==
  957. The two questions for scroll #1 were:
  958.  
  959. 1. How many husbands were shot on that fateful night?
  960. 2. Why is Queen Henrietta I revered in Mamajorca?
  961.  
  962. The answers are:
  963.  
  964. If there are n unfaithful husbands (UHs), every wife of an UH knows of
  965. n-1 UH's while every wife of a faithful husband knows of n UHs.  [this
  966. because everyone has perfect information about everything except the
  967. fidelity of their own husband].  Now we do a simple induction: Assume
  968. that there is only one UH.  Then all the wives but one know that there
  969. is just one UH, but the wife of the UH thinks that everyone is
  970. faithful.  Upon hearing that "there is at least one UH", the wife
  971. realizes that the only husband it can be is her own, and so shoots
  972. him.  Now, imagine that there are just two UH's.  Each wife of an UH
  973. assumes that the situation is "only one UH in town" and so waits to
  974. hear the other wife (she knows who it is, of course) shoot her husband
  975. on the first night.  When no one is shot, that can only be because her
  976. OWN husband was a second UH.  The wife of the second UH makes the same
  977. deduction when no shot is fired the first night (she was waiting, and
  978. expecting the other to shoot, too).  So they both figure it out after
  979. the first night, and shoot their husbands the second night.  It is
  980. easy to tidy up the induction to show that the n UHs will all be shot
  981. just on the n'th midnight.
  982.  
  983. The question for scroll #2 is:
  984.  
  985. 3. Why is Queen Henrietta II not?
  986.  
  987. The answer is:
  988.  
  989. The problem now is that QHII didn't realize that it is *critical* that
  990. all of the wives, of faithful and UH's alike, to
  991. *BEGIN*AT*THE*SAME*MOMENT*.  The uncertainty of having a particular
  992. wife's notice come a day or two late makes the whole logic path fall
  993. apart.  That's why she's foolish.  She is unjust, because some wives,
  994. honed and crack logicians all, remember, will *incorrectly* shoot
  995. faithful husbands.  Let us imagine the situation with just a SINGLE UH
  996. in the whole country.  And, wouldn't you know it, the notice to the
  997. wife of the UH just happens to be held up a day, whereas everyone
  998. else's arrived the first day.  Now, all of the wives that got the
  999. notice the first day know that there is just one UH in the country.
  1000. And they know that the wife of that UH will think that everyone is
  1001. faithful, and so they'll expect her to figure it out and shoot her
  1002. husband the first night.  BUT SHE DIDN"T GET THE NOTICE THE FIRST
  1003. NIGHT....  BUT THE OTHER WIVES HAVE NO WAY OF KNOWING THAT.  So, the
  1004. wife of the UH doesn't know that anything is going on and so (of
  1005. course) doesn't do anything the first night.  The next day she gets
  1006. the notice, figures it all out, and her husband will be history come
  1007. that midnight.  BUT... *every* other wife thought that there should
  1008. have been a shooting the first night, and since there wasn't there
  1009. must have been an additional UH, and it can only have been _her_
  1010. husband.  So on the second night **ALL** of the husbands are shot.
  1011. Things are much more complicated if the mix of who gets the notice
  1012. when is less simple than the one I mentioned above, but it is always
  1013. wrong and/or tragic.
  1014.  
  1015. NOTE: if the wives *know* that the country courier service (or however
  1016. these things get delivered) is flaky, then they can avoid the
  1017. massacre, but unless the wives exchange notes no one will ever be shot
  1018. (since there is always a chance that rather than _your_ husband being
  1019. an UH, you could reason that it might be that the wife of one of the
  1020. UH's that you know about just hasn't gotten her copy of the scroll
  1021. yet).  I guess you could call this case "unjust", too, since the UH's
  1022. evade punishment, despite the perfect logic of the wives.
  1023.  
  1024. ==> logic/locks.and.boxes.p <==
  1025. You want to send a valuable object to a friend.  You have a box which
  1026. is more than large enough to contain the object.  You have several
  1027. locks with keys.  The box has a locking ring which is more than large enough
  1028. to have a lock attached.  But your friend does not have the key to any
  1029. lock that you have.  How do you do it?  Note that you cannot send a key
  1030. in an unlocked box, since it might be copied.
  1031.  
  1032.  
  1033. ==> logic/locks.and.boxes.s <==
  1034. Attach a lock to the ring.  Send it to her.  She attaches her own lock
  1035. and sends it back.  You remove your lock and send it back to her.  She
  1036. removes her lock.
  1037.  
  1038. ==> logic/min.max.p <==
  1039. In a rectangular array of people, which will be taller, the tallest of the
  1040. shortest people in each column, or the shortest of the tallest people in each row?
  1041.  
  1042. ==> logic/min.max.s <==
  1043. Let T denote shortest of tall
  1044. Let S denote tallest of short
  1045.  
  1046. -------------------------------
  1047. |                             |
  1048. |                             |
  1049. |                S            |
  1050. |                             |
  1051. |                             |
  1052. |    T           X            |
  1053. |                             |
  1054. |                             |
  1055. |                             |
  1056. |                             |
  1057. -------------------------------
  1058.  
  1059. So T >= X >= S.
  1060.  
  1061.  
  1062. ==> logic/mixing.p <==
  1063. Start with a half cup of tea and a half cup of coffee. Take one tablespoon
  1064. of the tea and mix it in with the coffee. Take one tablespoon of this mixture
  1065. and mix it back in with the tea. Which of the two cups contains more of its
  1066. original contents?
  1067.  
  1068. ==> logic/mixing.s <==
  1069. Mixing Liquids
  1070.  
  1071. The two cups end up with the same volume of liquid they started with. The same
  1072. amount of tea was moved to the coffee cup as coffee to the teacup. Therefore
  1073. each cup contains the same amount of its original contents.
  1074.  
  1075. ==> logic/monty.52.p <==
  1076. Monty and Waldo play a game with N closed boxes.  Monty hides a
  1077. dollar in one box; the others are empty.  Monty opens the empty boxes
  1078. one by one.  When there are only two boxes left Waldo opens either box;
  1079. he wins if it contains the dollar.  Prior to each of the N-2 box
  1080. openings Waldo chooses one box and locks it, preventing Monty from opening
  1081. it next.  That box is then unlocked and cannot be so locked twice in a row.
  1082.  
  1083. What are the optimal strategies for Monty and Waldo and what is the
  1084. fair price for Waldo to pay to play the game?
  1085.  
  1086. ==> logic/monty.52.s <==
  1087. The fair price for large N is $0.6321205588285576784; I will offer
  1088. a proof along with optimal strategies.
  1089.  
  1090. Denote the game as G_N().  After (N-M) rounds of play, the game will have
  1091. the same form as G_M().  Depending on the strategies each of the M boxes
  1092. will have a probability p_i of containing the dollar.  Let Waldo lock
  1093. the M'th box (renumbering the boxes if necessary).  Denote the game and
  1094. Waldo's expected winnings in the game by
  1095.         G_M(p_1, p_2, ..., p_M)
  1096. where
  1097.         p_1 + p_2 + ... + p_M = 1
  1098.  
  1099. When
  1100.         p_2 = p_3 = p_4 = ... = p_M
  1101. we adopt the abbreviation
  1102.         G_M(b) = G_M(1 + b - Mb, b, b, b, b, ..., b)
  1103. and note that since probabilities are never negative:
  1104.         1 + b - Mb >= 0, or
  1105.         0 <= b <= 1 / (M-1)
  1106.  
  1107. Various G_M(p_1, p_2, ..., p_M) have difficult solutions but we are asked
  1108. only to solve G_M(1/M) and it turns out we can accomplish this by
  1109. considering only the games
  1110.         G_M(b)  where    1/M  <=  b  <=  1/(M-1)        [1]
  1111. Games of this form will be said to satisfy constraint [1].
  1112.  
  1113. Induction is used for one of the theorems, so we'd better solve G_2 and G_3
  1114. for our basis.
  1115.         G_2(p_1, p_2) = max (p_1, p_2)
  1116.         G_3(p_1, p_2, p_3) = max (p_1 + p_2, p_3)
  1117. since after Monty opens box #1, box #2 will have probability (p_1 + p_2)
  1118. and vice versa.  When the probabilities satisfy constraint [1]: 
  1119.         G_2(b) = G_2(1-b, b) = b
  1120.         G_3(b) = G_3(1-2b, b, b) = 1 - b
  1121.  
  1122. The proof of Theorem 1 is based on the probability p_i that box #i
  1123. contains the dollar.  (Of course this is Waldo's perceived probability:
  1124. Monty's probability would be 0 or 1.)  It may seem wrong for Waldo to
  1125. "forget" the game history and remember only the computed p_i.  For
  1126. example he may have previously locked some but not all of the boxes
  1127. and this fact is ignored except in the calculation of p_i.  Or Monty may
  1128. have some higher level "plan" which mightn't seem to translate directly
  1129. into probabilities.  But probability algebra obeys some simplifying
  1130. linearity rules and, if Monty keeps a "poker face", the probability model
  1131. is the only thing Waldo has to act on.
  1132.  
  1133. Especially paradoxical is the derivation of Waldo's p_i in his trivial
  1134. strategy below: he can adopt inferior but "correct" p_i to simplify the
  1135. analysis.
  1136.  
  1137. Theorem 1)
  1138.     If   b >= 1/M   then
  1139.     G_M(b) = G_[M-1]( (1-b) / (M-2) )
  1140.  
  1141. Proof)
  1142.     We will show that Monty and Waldo each have a strategy in G_M(b) to
  1143.     reduce the game to G_[M-1](b, q, q, ..., q) where q = (1-b) / (M-2)
  1144.     and where the boxes have been renumbered so that box #1 was box #M
  1145.     (the one Waldo locked) from the prior round and the new box #(M-1)
  1146.     is the one Waldo locks next.  Note that if Monty indeed arranges
  1147.     the probability mixture G_[M-1](b, q, q, q, q, ..., q) it won't
  1148.     matter which box Waldo locks (Box #1 has the only non-equal
  1149.     probability but Waldo cannot lock the same box twice in a row);
  1150.     this is a typical property of "saddlepoint" strategy.
  1151.  
  1152.     We will derive the necessary and sufficient condition for Monty to
  1153.     reduce any game G_M(p_1, p_2, p_3, ..., p_M) to a single game with
  1154.     the form G_[M-1](b, q, q, ..., q).  Using the numbering of G_M()
  1155.     let R(i,j) be the joint probability that Box #i contains the dollar
  1156.     and Box #j is opened by Monty in G_M().  We need consider only
  1157.         M >= 3
  1158.     Clearly,
  1159.         R(i, j) >= 0
  1160.         R(i, i) = 0
  1161.         R(i, M) = 0, i < M
  1162.         sum_over_j R(i,j) = p_i
  1163.     and to achieve q_2 = q_3 = ... = q_[M-1] in G_[M-1],
  1164.         R(1, j) = R(k, j)
  1165.             for 1 < j,k < M and j != k
  1166.         R(2, 1) = R(k, 1)
  1167.             for 2 < k < M
  1168.     and to make G_[M-1] be independent of Monty's play
  1169.         R(M, j)/R(1, j) = R(M, 2)/R(1, 2)
  1170.             for 2 < j < M
  1171.         R(M, 2)/R(1, 2) = R(M, 1)/R(2, 1)
  1172.  
  1173.     The above have a simple unique solution:
  1174.         R(i, j) = (1 - p_M) / (M - 2)  - p_j        [2]
  1175.             for i,j < M and i != j
  1176.         R(M, j) = p_M - p_j * p_M / (1 - p_M)        [3]
  1177.             for j < M
  1178.         p_j * (M-2) + p_M <= 1                [4]
  1179.  
  1180.     For the theorem we are given that G_M(b) satisfies constraint [1]
  1181.         1 / M  <=  b  <=  1 / (M - 1)
  1182.     which implies the weaker inequality
  1183.         (M - 3) / (M^2 - 3M + 1)  <=  b  <=  1 / (M - 1)
  1184.     and since for the constraint-[1] compliant G_M()
  1185.         p_j = b   or   p_j = (1+b-Mb)   for all j
  1186.     the inequality [4] follows directly.
  1187.  
  1188.     Hence Monty can transpose G_M(b) into G_[M-1]( (1-b) / (M-2) )
  1189.     whenever b >= 1/M and M >= 3.  (This G_[M-1] also happens to
  1190.     satisfy constraint [1] as needed for the next theorem.)
  1191.  
  1192.     It should be easy to argue that this strategy is optimal for Monty,
  1193.     but we want to derive Waldo's best strategy anyway and if it
  1194.     guarantees the same value we know we're at the "saddlepoint".
  1195.     If Waldo knows Monty has a non-optimal strategy he can take
  1196.     advantage of it, but we will just derive a strategy good enough
  1197.     to achieve the saddle-point value.
  1198.  
  1199.     Monty must transform G_M(b) into some
  1200.         G_[M-1](b, q_2, q_3, ..., q_[M-1])
  1201.     where Waldo has the choice of locking any of boxes #2 through #(M-1).
  1202.     If Waldo locks each of the (M-2) available boxes with probability
  1203.     1/(M-2) it is easily seen that the average probability that he
  1204.     locks the box with the dollar is (1-b) / (M-2) and the probabilities
  1205.     q_2, q_3, ..., q_[M-2] will also have the average value (1-b)/(M-2).
  1206.     If Waldo pretends to "forget" which box he picked before, he can
  1207.     take q_2 = q_3 = ... = (1-b)/(M-2) thereby constructing the same
  1208.     game Monty constructed with his saddlepoint strategy!
  1209.  
  1210.     In the above Waldo in effect "degraded" the accuracy of his
  1211.     probability estimates with the substitutions
  1212.         q_2' = (q_2 + q_3 + ... + q_[M-1]) / (M - 2)
  1213.         q_3' = (q_2 + q_3 + ... + q_[M-1]) / (M - 2)
  1214.           et cetera
  1215.     If Waldo "knows" more than this, he can pretend he doesn't!
  1216.     For example he can ask Monty to secretly shuffle the boxes.
  1217.  
  1218.     Thus either player can reduce
  1219.         G_M(b), b >= 1/M
  1220.     to
  1221.         G_[M-1]((1-b)/(M-2))
  1222.     so this must be the saddlepoint.
  1223.     Q.E.D.
  1224.  
  1225. Theorem 2)
  1226.     If   b >= 1/M   then
  1227.     G_M(b) = 1 - 1/2! + 1/3! - ... - (1-b)(-1)^M/(M-2)!
  1228.         = - sum (-1)^i/i! - (1-b)(-1)^M/(M-2)!
  1229.     where the sum is over i = 1, 2, 3, ..., M-3
  1230.  
  1231. Proof)
  1232.     The proof is by induction.  We know the theorem holds for M = 3
  1233.     and we will assume it holds for (M-1).  Set
  1234.         c = (1-b) / (M-2)
  1235.     We noted earlier that b <= 1/(M-1): otherwise p_1 = (1 + b - Mb)
  1236.     is negative; hence we obtain
  1237.         c = (1-b)/(M-2) >= (1 - 1/(M-1)) / (M-2)
  1238.     or simply
  1239.         c >= 1/(M-1)
  1240.     Thus the condition of the inductive hypothesis is satisfied and
  1241.         G_[M-1](c) = 1 - 1/2! + 1/3! - ... + (1-c)(-1)^M/(M-3)!
  1242.     But from Theorem 1
  1243.         G_M(b) = G_[M-1](c)
  1244.     and from the definition of c,
  1245.         c/(M-3)! = (1-b)/(M-2)!
  1246.     which establishes the theorem.
  1247.  
  1248. Theorem 3)
  1249.     G_M(1/M) = G_M(1/M, ..., 1/M) = 1 - 1/2! + 1/3! - ... -(-1)^M/M!
  1250.  
  1251. Proof)
  1252.     This follows directly from Theorem 2 and the observation that
  1253.         (1/M)/(M-2)! = 1/(M-1)! - 1/M!
  1254.  
  1255. For large M, G_M(1/M) approaches (1 - 1/e).  It will be a little bigger
  1256. when M is odd and a little smaller when M is even.  I've appended the
  1257. numeric values below.
  1258.  
  1259. % dc
  1260. [[Solution for M =]Plb1+pdsb]sy
  1261. 65k1sa1sblyx2sc[la1lc/-dsaplclyx*scla1lc/+dsaplclyx*sclzx]dszx
  1262. Solution for M =2
  1263. 0.50000000000000000000000000000000000000000000000000000000000000000
  1264. Solution for M =3
  1265. 0.66666666666666666666666666666666666666666666666666666666666666666
  1266. Solution for M =4
  1267. 0.62500000000000000000000000000000000000000000000000000000000000000
  1268. Solution for M =5
  1269. 0.63333333333333333333333333333333333333333333333333333333333333333
  1270. Solution for M =6
  1271. 0.63194444444444444444444444444444444444444444444444444444444444445
  1272. Solution for M =7
  1273. 0.63214285714285714285714285714285714285714285714285714285714285714
  1274. Solution for M =8
  1275. 0.63211805555555555555555555555555555555555555555555555555555555556
  1276. Solution for M =9
  1277. 0.63212081128747795414462081128747795414462081128747795414462081129
  1278. Solution for M =10
  1279. 0.63212053571428571428571428571428571428571428571428571428571428572
  1280.     . . .
  1281. Solution for M =52
  1282. 0.63212055882855767840447622983853913255418886896823216549216319831
  1283.  
  1284. P. S. There are related unsolved problems:
  1285. (a) what about G_M(p_1, p_2, ..., p_M) that do not fit the pattern used
  1286. in the above solution?
  1287. (b) what if two boxes contain dollars?  (first, what should the rules be?)
  1288.  
  1289. -- james@crc.ricoh.com (James Allen)
  1290.  
  1291. ==> logic/number.p <==
  1292. Mr. S. and Mr. P. are both perfect logicians, being able to correctly deduce
  1293. any truth from any set of axioms.  Two integers (not necessarily unique) are
  1294. somehow chosen such that each is within some specified range.  Mr. S.
  1295. is given the sum of these two integers; Mr. P. is given the product of these
  1296. two integers.  After receiving these numbers, the two logicians do not
  1297. have any communication at all except the following dialogue:
  1298. <<1>>   Mr. P.:  I do not know the two numbers.
  1299. <<2>>   Mr. S.:  I knew that you didn't know the two numbers.
  1300. <<3>>   Mr. P.:  Now I know the two numbers.
  1301. <<4>>   Mr. S.:  Now I know the two numbers.
  1302.  
  1303. Given that the above statements are absolutely truthful, what are the two
  1304. numbers?
  1305.  
  1306. ==> logic/number.s <==
  1307. The answer depends upon the ranges from which the numbers are chosen.
  1308.  
  1309. The unique solution for the ranges [2,62] through [2,500+] is:
  1310.  
  1311.   SUM   PRODUCT   X   Y
  1312.    17      52     4  13
  1313.  
  1314. The unique solution for the ranges [3,94] through [3,500+] is:
  1315.  
  1316.   SUM   PRODUCT   X   Y
  1317.    29     208    13  16
  1318.  
  1319. There are no unique solutions for the ranges starting with 1,
  1320. and there are no solutions for ranges starting with numbers above 3.
  1321.  
  1322. A program to compute the possible pairs is included below.
  1323.  
  1324. #include <stdio.h>
  1325.  
  1326. /*
  1327.  
  1328. BEGINNING OF PROBLEM STATEMENT:
  1329. Mr. S. and Mr. P. are both perfect logicians, being able to correctly deduce
  1330. any truth from any set of axioms.  Two integers (not necessarily unique) are
  1331. somehow chosen such that each is within some specified range.  Mr. S.
  1332. is given the sum of these two integers; Mr. P. is given the product of these
  1333. two integers.  After receiving these numbers, the two logicians do not
  1334. have any communication at all except the following dialogue:
  1335. <<1>>   Mr. P.:  I do not know the two numbers.
  1336. <<2>>   Mr. S.:  I knew that you didn't know the two numbers.
  1337. <<3>>   Mr. P.:  Now I know the two numbers.
  1338. <<4>>   Mr. S.:  Now I know the two numbers.
  1339.  
  1340. Given that the above statements are absolutely truthful, what are the two
  1341. numbers?
  1342.  
  1343. END OF PROBLEM STATEMENT
  1344.  
  1345.  */
  1346.  
  1347. #define SMALLEST_MIN    1
  1348. #define LARGEST_MIN    10
  1349. #define SMALLEST_MAX    50
  1350. #define LARGEST_MAX    500
  1351.  
  1352. long P[(LARGEST_MAX + 1) * (LARGEST_MAX + 1)];        /* products */
  1353. long S[(LARGEST_MAX + 1) + (LARGEST_MAX + 1)];        /*   sums   */
  1354.  
  1355. find(long min, long max)
  1356. {
  1357.     long i, j;
  1358.     /*
  1359.      *    count factorizations in P[]
  1360.      *    all P[n] > 1 satisfy <<1>>.
  1361.      */
  1362.     for(i = 0; i <= max * max; ++i)
  1363.         P[i] = 0;
  1364.  
  1365.     for(i = min; i <= max; ++i)
  1366.         for(j = i; j <= max; ++j)
  1367.             ++P[i * j];
  1368.  
  1369.     /*
  1370.      *    decompose possible SUMs and check factorizations
  1371.      *        all S[n] == min - 1 satisfy <<2>>.
  1372.      */
  1373.     for(i = min + min; i <= max + max; ++i) {
  1374.  
  1375.         for(j = i / 2; j >= min; --j)
  1376.             if(P[j * (i - j)] < 2)
  1377.                 break;
  1378.  
  1379.         S[i] = j;
  1380.     }
  1381.  
  1382.     /*
  1383.      *    decompose SUMs which satisfy <<2>> and see which products
  1384.      *    they produce.  All (P[n] / 1000 == 1) satisfy <<3>>.
  1385.      */
  1386.     for(i = min + min; i <= max + max; ++i)
  1387.         if(S[i] == min - 1)
  1388.             for(j = i / 2; j >= min; --j)
  1389.                 if(P[j * (i - j)] > 1)
  1390.                     P[j * (i - j)] += 1000;
  1391.     /*
  1392.      *    decompose SUMs which satisfy <<2>> again and see which products
  1393.      *    satisfy <<3>>.  Any (S[n] == 999 + min) satisfies <<4>>
  1394.      */
  1395.     for(i = min + min; i <= max + max; ++i)
  1396.         if(S[i] == min - 1)
  1397.             for(j = i / 2; j >= min; --j)
  1398.                 if(P[j * (i - j)] / 1000 == 1)
  1399.                     S[i] += 1000;
  1400.     /*
  1401.      *    find the answer(s) and print them
  1402.      */
  1403.     printf("[%d,%d]\n",min,max);
  1404.     for(i = min + min; i <= max + max; ++i)
  1405.         if(S[i] == 999 + min)
  1406.             for(j = i / 2; j >= min; --j)
  1407.                 if(P[j * (i - j)] / 1000 == 1)
  1408.                     printf("{ %d %d }: S = %d, P = %d\n",
  1409.                         i - j, j, i, (i - j)  * j);
  1410. }
  1411.  
  1412. main()
  1413. {
  1414.     long min, max;
  1415.  
  1416.     for (min = SMALLEST_MIN; min <= LARGEST_MIN; min ++)
  1417.         for (max = SMALLEST_MAX; max <= LARGEST_MAX; max++)
  1418.         find(min,max);
  1419. }
  1420.  
  1421. -------------------------------------------------------------------------
  1422. =            Jeff Kenton    (617) 894-4508            =
  1423. =                jkenton@world.std.com            =
  1424. -------------------------------------------------------------------------
  1425.  
  1426.