Re: Logic challenge (a REALLY tough problem)

new topic     » topic index » view thread      » older message » newer message

On Wed, 20 Feb 2002 15:11:29 +1100, Derek Parnell
<ddparnell at bigpond.com> wrote:

>
>20/02/2002 12:58:02 PM, petelomax at blueyonder.co.uk wrote:
>
>>
>>>The Shortest is Bernard
>>NOPE (and you were so close)
<snip>

>Also, there is not enough information to resolve whether C is taller than B or
>not

Correct!  I am very impressed you figured it out so quickly, bar that
minor slip up.


I found that puzzle in july 98 and at that time wrote two answers:


Two of Anthony, Bernard, and Charles are fighting each other.

1. The shorter of Anthony and Bernard is the older of the
   two fighters.

2. The younger of Bernard and Charles is the shorter of the 
   two fighters.

3. The taller of Anthony and Charles is the younger of the 
   two fighters.

Who is not fighting?*

 The Fight - From [1], Charles is not the older fighter. From 
[3], Bernard is not the younger fighter. So either:

Case 1. Anthony is the older fighter and Charles is the younger 
        fighter.
Case 2. Bernard is the older fighter and Anthony is the younger
        fighter.
Case 3. Bernard is the older fighter and Charles is the younger 
        fighter.

Then:
>From [3], Charles is the taller fighter for Case 1 and Charles 
is taller than Anthony for Case 3.

>From [1], Bernard is the shorter fighter for Case 2 and Bernard
is shorter than Anthony for Case 3.

>From [1] and [3], Charles is taller than Bernard for Case 3.

In summary:
          Older     Younger     Taller     Shorter
Case 1   Anthony    Charles     Charles    Anthony
Case 2   Bernard    Anthony     Anthony    Bernard
Case 3   Bernard    Charles     Charles    Bernard

>From [2], Anthony is not the shorter fighter; so Case 1 is 
eliminated. From [2], Bernard cannot be both older and shorter
than Charles so Case 3 is eliminated. Then Case 2 is the 
correct one and CHARLES is not fighting. 




I also wrote:

Two of Anthony, Bernard, and Charles are fighting each other.

1. The shorter of Anthony and Bernard is the older of the
   two fighters.

2. The younger of Bernard and Charles is the shorter of the 
   two fighters.

3. The taller of Anthony and Charles is the younger of the 
   two fighters.

Who is not fighting?*

First consider the six possibilities for who is the older and younger
fighter:

	   A       B       C       D       E       F
Older	Anthony	Anthony	Bernard	Bernard	Charles	Charles
Younger	Bernard	Charles	Anthony	Charles	Anthony	Bernard
	  [3] 				  [1]   [1],[3]

We can rule out A, E and F as shown because from [3] Bernard is not
the younger fighter and from [1] Charles is not the older fighter.

If B is true (Anthony is the older fighter and Charles is the younger
fighter), then from [3] Charles would be the taller fighter but from
[2] Anthony is not the shorter fighter.

If D is true (Bernard is the older fighter and Charles is the younger
fighter), then from [3] Charles is taller than Anthony and from [1]
Bernard is shorter than Anthony, which means that Charles is taller
than Bernard. However from [2] that would make Bernard the younger
fighter so that case is also eliminated.

Hence Charles is not fighting, Bernard is the older and shorter
fighter and Anthony is the younger and taller fighter.





But then again that was July 1998 so yesterday I wrote:

constant A=1, B=2, C=3	-- ANTHONY, BERNARD, CHARLES
sequence a, h, f		-- age, height, fighter
constant permutes={
	{1,2,3},
	{1,3,2},
	{2,1,3},
	{2,3,1},
	{3,1,2},
	{3,2,1}
		 }

integer caseproven

for ai=1 to 6 do
	a=permutes[ai]
	for hi=1 to 6 do
		h=permutes[hi]
		for fi = 2 to 4 do		-- any three cases where:
			f=permutes[fi]-1	-- 0 means not fighting
--
-- Now test the conditions
--
			caseproven=1 -- assume true
--
-- 1. The shorter of Anthony and Bernard is the older of the two
fighters.
--
			if h[A] < h[B] then
				if not f[A] then caseproven=0 end if
				if f[B] then
					if a[A] < a[B] then caseproven=0 end if
				else -- f[C]
					if a[A] < a[C] then caseproven=0 end if
				end if
			else -- h[B] < h[A]				
				if not f[B] then caseproven=0 end if
				if f[A] then
					if a[B] < a[A] then caseproven=0 end if
				else -- f[C]
					if a[B] < a[C] then caseproven=0 end if
				end if
			end if
--
-- 2. The younger of Bernard and Charles is the shorter of the two
fighters.
--
			if a[B] < a[C] then
				if not f[B] then caseproven=0 end if
				if f[A] then
					if h[B] > h[A] then caseproven=0 end if
				else -- f[C]
					if h[B] > h[C] then caseproven=0 end if
				end if
			else -- a[C] < a[B]				
				if not f[C] then caseproven=0 end if
				if f[A] then
					if h[C] > h[A] then caseproven=0 end if
				else -- f[B]
					if h[C] > h[B] then caseproven=0 end if
				end if
			end if			
--
-- 3. The taller of Anthony and Charles is the younger of the two
fighters.
--
			if h[A] > h[C] then
				if not f[A] then caseproven=0 end if
				if f[B] then
					if a[A] > a[B] then caseproven=0 end if
				else -- f[C]
					if a[A] > a[C] then caseproven=0 end if
				end if
			else -- h[C] > h[A]				
				if f[C] then caseproven=0 end if
				if f[A] then
					if a[C] > a[A] then caseproven=0 end if
				else -- f[B]
					if a[C] > a[B] then caseproven=0 end if
				end if
			end if				
			if caseproven then
printf(1,"Anthony: age %d height %d fighter %d\n",{a[A],h[A],f[A]})
printf(1,"Bernard: age %d height %d fighter %d\n",{a[B],h[B],f[B]})
printf(1,"Charles: age %d height %d fighter %d\n",{a[C],h[C],f[C]})
			end if
		end for
	end for
end for	


Obviously tests for rules 1,2, and 3 are very symetrical. I was going
to try & get clever/merge/obfuscate them but then I had to ask myself
"WHY DO I WASTE MY TIME ON THINGS LIKE THIS WHEN I HAVE SO MANY OTHER
THINGS I HAVE TO (OR JUST REALLY WANT TO) DO?" Anyway, feel free :=)



Pete
Qu: will this p Rob off for being off-topic of will he have to let it
slide because it contains Euphoria code?

(OK, I admit, see alt.lang.euphoria for why we might possibly
occasionally need a guiding hand...)

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu