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
 Funny Test IV

Author  Topic 

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2004-09-06 : 16:42:01
By request after FT III:

/*
declare @n int
set @n = 13
-- write sql to calculate 13th fibonacci number,
-- using at the most one more variable apart from @n,
-- no tables of any kind are allowed

--*/

rockmoose
/* Chaos is the nature of things...Order is a lesser state of chaos */

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-09-06 : 18:47:53
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=30761

Been done



Damian
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2004-09-07 : 00:59:09
Ok Granted, it's been done... with tables ...
And we can rule out all the solutions with tables involved.
Did I miss a solution without a table somewhere

This was your solution Damian, but it disqualifies because of the Sequence table, sorry..

quote:
originally posted by MerekinDeclare @phi float
Select @phi = (1 + Sqrt(5))/2

SELECT
CAST( (POWER(@phi, seq) - POWER(-1/@Phi, seq )) / Sqrt(5) as int )
FROM Sequence
WHERE seq < 21



rockmoose
/* Chaos is the nature of things...Order is a lesser state of chaos */
Go to Top of Page

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2004-09-07 : 03:54:54
rockmoose knows Binet formulae
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2004-09-07 : 04:04:53
sooo easy...

(special for Merkin)

declare @n int
set @n = 13

--depends on whether you start with 1, 1 or 1, 2 but anyhoo
select ceiling(exp(log(@n)* pi() - log(@n)) - (@n - 2*log10(@n)))




PS http://mathworld.wolfram.com/BinetsFibonacciNumberFormula.html
--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2004-09-07 : 04:33:49
quote:
Originally posted by Stoad

rockmoose knows Binet formulae



uuuumhmhu Binet ?!?! heard of it now....

You guys freak me out,
next time I will search Mathworld before posting anything

Edit: rrb your formula doesnt work! Stoad Wins


( I will promptly proceed to decipher the formula )
( And honorable mentions to stoad who was too lazy to do the SQL )

Here follows my humble solution:

--/*
declare @n int
set @n = 13
-- write sql to calculate 13th fibonacci number,
-- using at the most one more variable apart from @n,
-- no tables of any kind are allowed

declare @f varchar(40)
set @f = '1,1'

while @n > 2 select
@n = @n - 1,
@f = right(@f,len(@f)-charindex(',',@f)) + ',' + ltrim(
cast(left(@f,charindex(',',@f)-1) as int) + cast(right(@f,len(@f)-charindex(',',@f)) as int))

select right(@f,len(@f)-charindex(',',@f)) as [nth fibonacci]

--*/


rockmoose
/* Chaos is the nature of things...Order is a lesser state of chaos */
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2004-09-07 : 06:47:14
Hey - I don't win. My formula is pure mathematical humour!

Stoad wins - he posted Binets before I did!



PS - I really was hoping someone would actually try my formula though...it works for 13!

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2004-09-07 : 06:56:18
quote:
Originally posted by rrb

Hey - I don't win. My formula is pure mathematical humour!

Stoad wins - he posted Binets before I did!

PS - I really was hoping someone would actually try my formula though...it works for 13!



Ok, yeah! works for 13.... good job rrb !

Never trust anyone... Unlearn...
/rockmoose
Go to Top of Page

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2004-09-07 : 08:06:36
I never posted Binets!

Binet, rockmoose & rrb share the 1st place.
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2004-09-07 : 08:26:41
Ok... here goes

declare @n int
set @n = 13

select floor((power((1+sqrt(5)),@n)-power((1-sqrt(5)),@n))/(power(2,@n)*sqrt(5)))




I can't win because I posted the darn puzzle !
Binet won, and he won in 1843 !!! geeze...

Who wants another puzzle ?


rockmoose
/* Chaos is the nature of things...Order is a lesser state of chaos */
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-09-07 : 08:43:04
Another puzzle!! Yeah!!!

Corey
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2004-09-07 : 14:45:17
New one:
[url]http://sqlteam.com/forums/topic.asp?TOPIC_ID=39535[/url]

rockmoose
/* Chaos is the nature of things...Order is a lesser state of chaos */
Go to Top of Page
   

- Advertisement -