Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Site Related Forums
 The Yak Corral
 Speaking of puzzles

Author  Topic 

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-02-21 : 15:57:12
Unfortunately, I don't think this is a SQL puzzle, so please do not get to excited.

However, I recently stumbled upon a great logic puzzle, actually its a quiz. Anyway, I figured some of the brilliant but restless minds would love to try their hand at it .

So Enjoy: http://www.funtrivia.com/quizdetails.cfm?quiz=70608

Corey

"If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-02-22 : 06:33:28

-16



rockmoose
Go to Top of Page

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2005-02-22 : 07:07:33
You scored: 2 / 10
Total points: 20
The average score for this quiz: 2 / 10
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-02-22 : 07:18:44
I haven't submitted any answers yet.... I just started on it yesterday

I let you know how bad I do

Corey

"If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-02-22 : 07:34:30
I have 1 correct answer (in SQL),
it is probably the only answer, but I don't know why that would be so.
10/10

rockmoose
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-02-22 : 07:54:09
in sql moose?? heh....
when i try to submit the answers i get a timeout

Go with the flow & have fun! Else fight the flow
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-02-22 : 08:42:52
>> when i try to submit the answers i get a timeout
Before I started to use the brain the calculations took a few minutes, yes.

stoad, I can't find the link to the send more money thread, got the link?
a friend at work was interested.




rockmoose
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-02-23 : 15:54:59
Not much activity here..
Here is one solution:
It assumes that answer to q10 is numeric, if q10 is T/F then the cases will be slightky different, and q8.a % 5 = 0.
I ran tests for q10 T/F, but I did not find any answers.
the number range in the tally table defines the number range for which possible solutions are searched.

set nocount on
create table n(a int primary key clustered)
create table b(a char(1) primary key clustered)
insert b select 'T' union select 'F'

truncate table n
insert n(a) select number - 20 from master.dbo.spt_values where type = 'P' and number <= 40

/*ASSUMES : Answer to q10 is Integer
restriction
q8.a <> 0
and q8.a % 6 = 0
after variable substitution
q1.a = q8.a*q8.a
q2.a = -(q4.a+(q8.a/6)*(q8.a+6)+q10a.a)
q6.a = q8.a*q8.a/6 */

select
q8.a*q8.a as q1
,-(q4.a+(q8.a/6)*(q8.a+6)+q10a.a) as q2
,q3.a as q3
,q4.a as q4
,q5.a as q5
,q8.a*q8.a/6 as q6
,q7.a as q7
,q8.a as q8
,q9.a as q9
,q10a.a as q10a
from
--n q1
--n q2
b q3
,n q4
,b q5
--,n q6
,b q7
,n q8
,b q9
,n q10a
where
(
q8.a <> 0
and q8.a % 6 = 0
and(-(q4.a+(q8.a/6)*(q8.a+6)+q10a.a) =
case q3.a when 'T' then 1 else 0 end
+case q5.a when 'T' then 1 else 0 end
+case q7.a when 'T' then 1 else 0 end
+case q9.a when 'T' then 1 else 0 end)
and(q3.a = case when q8.a*q8.a>-(q4.a+(q8.a/6)*(q8.a+6)+q10a.a) and q8.a*q8.a>q4.a and q8.a*q8.a>q10a.a then 'T' else 'F' end)
and(q4.a =
1+case when q4.a=q8.a*q8.a then 1 else 0 end
+case when q4.a=-(q4.a+(q8.a/6)*(q8.a+6)+q10a.a) then 1 else 0 end
+case when q4.a=q8.a*q8.a/6 then 1 else 0 end
+case when q4.a=q8.a then 1 else 0 end
+case when q4.a=q10a.a then 1 else 0 end)
and(q5.a = case when -(q4.a+(q8.a/6)*(q8.a+6)+q10a.a)>=0 and q4.a>0 and q8.a>0 and q10a.a>0 then 'T' else 'F' end)
and(q7.a = case when q4.a>-(q4.a+(q8.a/6)*(q8.a+6)+q10a.a) then 'T' else 'F' end)
and(q9.a = case when q8.a*q8.a/6 = ((-(q4.a+(q8.a/6)*(q8.a+6)+q10a.a)-q4.a)-(q8.a*q4.a)) then 'T' else 'F' end)
)

drop table n
drop table b


rockmoose
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-02-23 : 17:00:59
I didn't have much luck doing it with sql either. I plan on revisiting it again soon ... Here is my attempt:



Declare @msg nvarchar(1000)

Set @Msg = convert(nvarchar,getdate(),101) + ' ' + convert(nvarchar,getdate(),108) + '--------------------------------------------------------------------------'
RaisError(@Msg,0,1) With NOWAIT

Set @Msg = convert(nvarchar,getdate(),101) + ' ' + convert(nvarchar,getdate(),108) + ' - Begin Solving'
RaisError(@Msg,0,1) With NOWAIT

Declare @ints table (val int)
Insert Into @ints
Select distinct val=(n1+n2+n3+n4+n5+n6+n7)*n0
From
(Select n0=-1 Union Select 1) n0,
(Select n1=0 Union Select 1) n1,
(Select n2=0 Union Select 2) n2,
(Select n3=0 Union Select 4) n3,
(Select n4=0 Union Select 8) n4,
(Select n5=0 Union Select 16) n5,
(Select n6=0 Union Select 32) n6,
(Select n7=0 Union Select 64) n7
Order By val

Set @Msg = convert(nvarchar,getdate(),101) + ' ' + convert(nvarchar,getdate(),108) + ' - built numbers table'
RaisError(@Msg,0,1) With NOWAIT

Declare @step1a table (q1 int, q2 int, q3 int, q4 int, q5 int, q6 int, q7 int, q8 int, q9 int, q10 int)

Insert Into @step1a
Select *
From
(Select q1 = val From @ints Where val in (0,1,4,9,16,25,36,49,64,81,100)) q1,
(Select q2 = val From @ints Where val between 0 and 4) q2,
(Select q3 = val From @ints where val in (0,1)) q3,
(Select q4 = val From @ints Where val between 0 and 6) q4,
(Select q5 = val From @ints where val in (0)) q5, -- Always false
(Select q6 = val From @ints Where val between -10 and 10) q6,
(Select q7 = val From @ints where val in (0,1)) q7,
(Select q8 = val From @ints Where val between -10 and 10) q8,
(Select q9 = val From @ints where val in (0,1)) q9,
(Select q10 = val From @ints) q10
Where q1=q8*q8
and q2+q4+q6+q8+q10=0
and q2=q3+q5+q7+q9
and q6=(q1+q2+q4+q6+q8+q10)/6.0
and q3=case when q1>q2 and q1>q4 and q1>q6 and q1>q8 and q1>q10 then 1 else 0 end
and q7=case when q4>q2 then 1 else 0 end
and q9 = case when q6 = abs(q2-q4)-(q4*q8) then 1 else 0 end

Select * From @step1a

Set @Msg = convert(nvarchar,getdate(),101) + ' ' + convert(nvarchar,getdate(),108) + ' - first pass w/ 10 assumed integer'
RaisError(@Msg,0,1) With NOWAIT


Select *
From @step1a
Where q4 = (
case when q1=q4 then 1 else 0 end+
case when q2=q4 then 1 else 0 end+
case when q4=q4 then 1 else 0 end+
case when q6=q4 then 1 else 0 end+
case when q8=q4 then 1 else 0 end+
case when q10=q4 then 1 else 0 end)


Set @Msg = convert(nvarchar,getdate(),101) + ' ' + convert(nvarchar,getdate(),108) + ' - second pass w/ 10 assumed integer'
RaisError(@Msg,0,1) With NOWAIT


Corey

"If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-02-23 : 17:14:59
Oh, mine works.
Your number table is slightly too small.

rockmoose
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-02-23 : 21:19:20
Wahoo!!!! mine worked too... a few slight mods:


Declare @msg nvarchar(1000)

Set @Msg = convert(nvarchar,getdate(),101) + ' ' + convert(nvarchar,getdate(),108) + '--------------------------------------------------------------------------'
RaisError(@Msg,0,1) With NOWAIT

Set @Msg = convert(nvarchar,getdate(),101) + ' ' + convert(nvarchar,getdate(),108) + ' - Begin Solving'
RaisError(@Msg,0,1) With NOWAIT

Declare @ints table (val int)
Insert Into @ints
Select distinct val=(n1+n2+n3+n4+n5+n6+n7+n8)*n0
From
(Select n0=-1 Union Select 1) n0,
(Select n1=0 Union Select 1) n1,
(Select n2=0 Union Select 2) n2,
(Select n3=0 Union Select 4) n3,
(Select n4=0 Union Select 8) n4,
(Select n5=0 Union Select 16) n5,
(Select n6=0 Union Select 32) n6,
(Select n7=0 Union Select 64) n7,
(Select n8=0 Union Select 128) n8
Order By val

Set @Msg = convert(nvarchar,getdate(),101) + ' ' + convert(nvarchar,getdate(),108) + ' - built numbers table'
RaisError(@Msg,0,1) With NOWAIT

Declare @step1a table (q1 int, q2 int, q3 int, q4 int, q5 int, q6 int, q7 int, q8 int, q9 int, q10 int)

Insert Into @step1a
Select q1, q2, q3, q4, q5, q6, q7, q8, q9, q10
From
(Select q2 = val From @ints Where val between 0 and 4) q2,
(Select q3 = val From @ints where val in (0,1)) q3,
(Select q4 = val From @ints Where val between 0 and 6) q4,
(Select q5 = val From @ints where val in (0)) q5, -- Always false
(Select q6 = val From @ints where val between -10 and 40) q6,
(Select q7 = val From @ints where val in (0,1)) q7,
(Select q1 = val*val, q8 = val From @ints Where abs(val) between 0 and 15) q8,
(Select q9 = val From @ints where val in (0,1)) q9,
(Select q10 = val From @ints where val between -30 and 30) q10
Where q1=q8*q8
and q2+q4+q6+q8+q10=0
and q2=q3+q5+q7+q9
and q6=(q1+q2+q4+q6+q8+q10)/6.0
and q3=case when q1>q2 and q1>q4 and q1>q6 and q1>q8 and q1>q10 then 1 else 0 end
and q7=case when q4>q2 then 1 else 0 end
and q9 = case when q6 = abs(q2-q4)-(q4*q8) then 1 else 0 end
and q4 = (
case when q1=q4 then 1 else 0 end+
case when q2=q4 then 1 else 0 end+
case when q4=q4 then 1 else 0 end+
case when q6=q4 then 1 else 0 end+
case when q8=q4 then 1 else 0 end+
case when q10=q4 then 1 else 0 end)

Select * From @step1a

Set @Msg = convert(nvarchar,getdate(),101) + ' ' + convert(nvarchar,getdate(),108) + ' - second pass w/ 10 assumed integer'
RaisError(@Msg,0,1) With NOWAIT


It found solution in 18sec on my home cpu...

Corey

"If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-02-24 : 02:52:48
The amazing problems one can solve with SQL !!!

Mine takes < 1 sec, I go straight for the assumption that q10 is numeric.
Yours is 18sec on my homepc as well.
(I found no solutions when q10 = T/F)

rockmoose
Go to Top of Page

Xerxes
Aged Yak Warrior

666 Posts

Posted - 2005-02-24 : 13:46:00
quote:
Originally posted by Seventhnight

Unfortunately, I don't think this is a SQL puzzle, so please do not get to excited.

However, I recently stumbled upon a great logic puzzle, actually its a quiz. Anyway, I figured some of the brilliant but restless minds would love to try their hand at it .

So Enjoy: http://www.funtrivia.com/quizdetails.cfm?quiz=70608

Corey

"If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain




I guess you just have to be a VULCAN to understand what it was that was being asked in the quiz in the first place! I was---as you may have suspected --- completely and utterly lost. Why this is, I don't know. I like to think I'm pretty smart myself. HOWEVER, where discerning the plausibility of the quiz may have eluded my grasp, I can still name every Roman Emperor, and term of office, and every President & VP and terms, the nearest 26 stars (by their constellational term),, all 88 constellations, at least 10 cities in every state, the names of the SCOTUS, the USConstitutional amendments, and the names of all 7 of my kids etc. Just wish I was a math whiz the way you and the 'Moose are!

WOW! I'm impressed! Ok, I'm envious too!

Semper fi,

Xerxes, USMC(Ret.)
------------------------------------------------------
Once a Marine ALWAYS a Marine!
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-02-24 : 16:32:27
>> I can still name every Roman Emperor, and term of office, and every President & VP and terms, the nearest 26 stars (by their constellational term),, all 88 constellations, at least 10 cities in every state, the names of the SCOTUS, the USConstitutional amendments

Now, THAT seems difficult to me...

rockmoose
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-02-24 : 16:36:12
I can say the English alphabet backwards in <5 secs

.... now if only I could say it forwards

Corey

"If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain
Go to Top of Page

Xerxes
Aged Yak Warrior

666 Posts

Posted - 2005-02-24 : 23:00:48
ROTFL You two guys just slay me!

I'm still envious...oh, by the way, here's another Idea for a puzzle of sorts. I've been fascinated all my life by PI (no, not the boysenberry kind---although that IS good!).

Below is a piece of Clipper code that processes the PI contrivance sequence: PI = 4/1 - (4/3) + (4/5) - (4/7) + (4/9) - (4/11) ...

(although Sqrt ( 12 - (12/22) + (12/32) - (12/42) + .. is faster)

clear
set decimals to 15
XYZ = space(30)
XX = ' '
CTR = 1
INC = 2
KK = 0.000000000000000
VV = 0.000000000000000
SIGN = .f.
KEY = ' '
Do WHILE KEY <> 'STOP'
KK = iif(SIGN,-(4/ctr),+(4/ctr)) /* if sign (.t.) do -(4/ctr) */
VV = VV + KK
XX = iif(SIGN, '-', '+')
CTR = CTR + INC
SIGN = IIF(SIGN,.f.,.t.) /* if SIGN is .f. set to .t. & viceversa
enddo


What I am attempting to do is find other equally efficient ratio for finding PI without guessing and testing. For example these are well known:

a. 22 / 7 is accurate to 0.04025%
b. 355 / 113 is better: it is accurate to 0.00000849%
c. 104348 / 33215 is even BETTER! It is accurate to 0.00000001056%

On my own I've found these:

p. 400,000,000 / 127,323,955 which is accurate to 7 digits
q. 2,443,463 / 777,777 accurate to 5 digits
r. 1,111,976 / 353,953 also accurate to 5 digits.

I'd like to find another way to find other 'gems' but my old Clipper routine is all I have.

Would you masterminds have any other ideas to solve this little puzzle?

Semper fi,

XERXES, USMC(Ret.)
------------------------------------------------------
The Marine Corps taught me everything but SQL!
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-02-25 : 07:19:24
ok corey, do some bisection...


Go with the flow & have fun! Else fight the flow
Go to Top of Page

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2005-02-25 : 16:12:52
Pity but it's too complex for me.....
How about my last corral problem (that passed unnoticed)?

Can a given rectangle with sides (a, b; a <= b) be placed
inside of another ("bigger") one with sides (c, d; c <= d)
???
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-02-25 : 16:46:41
>> (that passed unnoticed)?
umh, Yes, at least by me... now I will have to use the search feature, hmmmm.
I am also looking for the send more money thing.

Xerxes, I think I have to think&work some on the PI stuff....
BTW: This calculates pi to 6 decimal!



rockmoose
Go to Top of Page

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2005-02-25 : 17:06:26
ah... "send more money"!.. it's somewhere in T-SQL forum (?)
Go to Top of Page
   

- Advertisement -