- #light
- let fibs = Seq.unfold (fun (n0, n1) -> Some(n0, (n1, n0 + n1))) (1I,1I)
- let first n = Seq.take n fibs
Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
Forum Search
Highly Rated Users
Forum Statistics
UsersTotal Post History
- Posts:
- 45705
- Topics:
- 9398
7-Day Post History
- New Posts:
- 343
- New Topics:
- 81
- Active Topics:
- 90
Our newest member
Other
-
FAQ
All times are UTC [ DST ]
Google Ads
LTD Puzzle 5: Calculating the Fibonacci Sequence
Forum rules
Always post answers in a "Hidecode" tag, so that others have a chance to answer the question too.
Always post answers in a "Hidecode" tag, so that others have a chance to answer the question too.
13 posts • Page 1 of 1
Please wait...
LTD Puzzle 5: Calculating the Fibonacci Sequence
This weeks puzzle is a nice and simple one to ease all those with sore heads from the July 4th celebrations back into thinking code...
If you've read the Dan Brown book "The Da Vinci Code" then you'll be quite familiar with this already... we would like you to calculate 'X' numbers in the Fibonacci Sequence, which is essentially adding the previous 2 occurring numbers together to make the next .. e.g. 0,1,1,2,3,5,8,13,21,34,55,89,....etc.
have fun...
p.s. don't forget to use the new [hidecode] tag to hide your code and highlight the syntax
If you've read the Dan Brown book "The Da Vinci Code" then you'll be quite familiar with this already... we would like you to calculate 'X' numbers in the Fibonacci Sequence, which is essentially adding the previous 2 occurring numbers together to make the next .. e.g. 0,1,1,2,3,5,8,13,21,34,55,89,....etc.
- Code should accept a single parameter to set the amount of numbers in the sequence to calculate, e.g. first 10 numbers, first 100, etc
- Format of output should be simply a list of numbers separated by a comma between each number; e.g. 0,1,1,2,3,5,8 etc..
- Interesting Variations score more points of course

- Sequence always starts at 0,1 - so minimum sequence length is 2.
have fun...

p.s. don't forget to use the new [hidecode] tag to hide your code and highlight the syntax
a smile is worth a thousand kind words, so smile, it's easy! 
CODE: $5
WORKING CODE: $500
PROPERLY DESIGNED & WORKING CODE: Priceless

CODE: $5
WORKING CODE: $500
PROPERLY DESIGNED & WORKING CODE: Priceless
-

damber - LTD Admin

-





- Posts: 1959
- Joined: Tue Oct 09, 2007 1:48 pm
- Location: North Wales, UK
Re: LTD Puzzle 5: Calculating the Fibonacci Sequence
this is a quick and dirty example in vb.net.
Max iterations is apparently with int64
Max iterations is apparently with int64
Code is hidden, SHOW
-

chrissie1 - LTD Admin

-










- Posts: 6038
- Joined: Wed Oct 10, 2007 7:18 pm
- Location: Belgium
Re: LTD Puzzle 5: Calculating the Fibonacci Sequence
-

chrissie1 - LTD Admin

-










- Posts: 6038
- Joined: Wed Oct 10, 2007 7:18 pm
- Location: Belgium
Re: LTD Puzzle 5: Calculating the Fibonacci Sequence
Code is hidden, SHOW
And we have contraptions like computers that cheat you out of becoming. Bill Gates says, "Wait till you see what your computer can become." But it's you who should be doing the becoming, not the damn fool computer.
My Crummy Web Page
My Crummy Web Page
-

AlexCuse - LTD Admin

-








- Posts: 3532
- Joined: Tue Oct 09, 2007 5:26 pm
- Location: Pennsylvania, US
Re: LTD Puzzle 5: Calculating the Fibonacci Sequence
A not particularly exciting VB6 version...
Code is hidden, SHOW
Andy
-

HarleyQuinn - LTD Admin

-
- Posts: 308
- Joined: Tue Dec 18, 2007 3:14 pm
- Location: Sheffield, UK
Re: LTD Puzzle 5: Calculating the Fibonacci Sequence
I have two entries, since neither approach has been posted yet.
First, a C# .NET 3.5 approach using IEnumerable.
And, here's a C++/CLI version that uses template meta-programming. This causes the compiler to compute all the math and unroll the loops, so the actual executed code is doing nothing more than printing the numbers. Changing to native C++ would be a matter of changing Console::WriteLine() to printf() function, updating the main() signature to main(int argc, const char *argv[]), and replacing "using ..." with "#include <stdlib.h>".
First, a C# .NET 3.5 approach using IEnumerable.
Code is hidden, SHOW
And, here's a C++/CLI version that uses template meta-programming. This causes the compiler to compute all the math and unroll the loops, so the actual executed code is doing nothing more than printing the numbers. Changing to native C++ would be a matter of changing Console::WriteLine() to printf() function, updating the main() signature to main(int argc, const char *argv[]), and replacing "using ..." with "#include <stdlib.h>".
Code is hidden, SHOW
-

spoulson - Senior Apprentice

-


- Posts: 203
- Joined: Mon Jun 02, 2008 2:37 am
- Location: Middletown, DE, USA
Re: LTD Puzzle 5: Calculating the Fibonacci Sequence
Another VB6 version.
Unlike all the other submissions, this version can calculate fibonacci numbers that are very long without losing any significant digits (like using the double/float data type). I tested this with calculating the first 10,000 fibonacci number. This version is probably limited to the amount of text that can fit in to a vb6 text box.
Unlike all the other submissions, this version can calculate fibonacci numbers that are very long without losing any significant digits (like using the double/float data type). I tested this with calculating the first 10,000 fibonacci number. This version is probably limited to the amount of text that can fit in to a vb6 text box.
Code is hidden, SHOW
-George
-

gmmastros - LTD Admin

-










- Posts: 1184
- Joined: Tue Oct 09, 2007 5:19 pm
Re: LTD Puzzle 5: Calculating the Fibonacci Sequence
Nice one George, I originally went with an array solution but dropped it for the shorter code (I've given you a point as I didn't have time to make either of my solutions as nicely outputted as yours!) 
Plus, the limitation of a textbox is gotten around by outputting to a file and that's probably only one more line of code if you're going absolutely minimal

Plus, the limitation of a textbox is gotten around by outputting to a file and that's probably only one more line of code if you're going absolutely minimal

Andy
-

HarleyQuinn - LTD Admin

-
- Posts: 308
- Joined: Tue Dec 18, 2007 3:14 pm
- Location: Sheffield, UK
Re: LTD Puzzle 5: Calculating the Fibonacci Sequence
Hi,
what about a lazy functional solution written with F#?
Claudio
http://www.fsharp.it
what about a lazy functional solution written with F#?
Code is hidden, SHOW
Claudio
http://www.fsharp.it
- sembee
- Newbie

-
- Posts: 1
- Joined: Wed Jul 09, 2008 9:53 am
Re: LTD Puzzle 5: Calculating the Fibonacci Sequence
That's awesome sembee. That very thing came to mind last night when I was trying to focus on school work (I had tried going down that road for the prime number puzzle, but found that sequence was not really orderly enough to use that particular function effectively).
And we have contraptions like computers that cheat you out of becoming. Bill Gates says, "Wait till you see what your computer can become." But it's you who should be doing the becoming, not the damn fool computer.
My Crummy Web Page
My Crummy Web Page
-

AlexCuse - LTD Admin

-








- Posts: 3532
- Joined: Tue Oct 09, 2007 5:26 pm
- Location: Pennsylvania, US
Re: LTD Puzzle 5: Calculating the Fibonacci Sequence
[hide]Sub Fibonacci()
Dim A, B
A = CDec(0)
B = CDec(1)
On Error GoTo Fibonacci_Exit
Do
Debug.Print A
B = B + A
Debug.Print B
A = A + B
Loop
Fibonacci_Exit:
End Sub[/hide]
it calculates up to 50095301248058391139327916261, the 140th term. That's 50 octillion!
Dim A, B
A = CDec(0)
B = CDec(1)
On Error GoTo Fibonacci_Exit
Do
Debug.Print A
B = B + A
Debug.Print B
A = A + B
Loop
Fibonacci_Exit:
End Sub[/hide]
it calculates up to 50095301248058391139327916261, the 140th term. That's 50 octillion!
It's more cheesier if you do it right the first time!
-

Emtucifor - Senior Sage

-










- Posts: 2152
- Joined: Fri May 30, 2008 9:30 pm
- Location: California
Re: LTD Puzzle 5: Calculating the Fibonacci Sequence
There are 2 types of winner - a "People's Champion" (the one with the most rating points across all their posts) and the LTD Admin's Champion (selected with our special formula....honest...well, maybe it's just the ones that the admins thought were particularly good
)
So...
People's Champion: sembee scoring 13 points for his very short and sweet answer.
LTD Admin's Champion: George for using strings to get the job done.
Congratulations to all.. and good luck on next weeks puzzle
)So...
People's Champion: sembee scoring 13 points for his very short and sweet answer.
LTD Admin's Champion: George for using strings to get the job done.
Congratulations to all.. and good luck on next weeks puzzle

-

chrissie1 - LTD Admin

-










- Posts: 6038
- Joined: Wed Oct 10, 2007 7:18 pm
- Location: Belgium
Re: LTD Puzzle 5: Calculating the Fibonacci Sequence
My solution in PHP:
Output (first 10 lines):
Code is hidden, SHOW
Output (first 10 lines):
- FibonacciSequence(2): 0,1,1
- FibonacciSequence(3): 0,1,1,2
- FibonacciSequence(4): 0,1,1,2,3
- FibonacciSequence(5): 0,1,1,2,3,5
- FibonacciSequence(6): 0,1,1,2,3,5,8
- FibonacciSequence(7): 0,1,1,2,3,5,8,13
- FibonacciSequence(8): 0,1,1,2,3,5,8,13,21
- FibonacciSequence(9): 0,1,1,2,3,5,8,13,21,34
- FibonacciSequence(10): 0,1,1,2,3,5,8,13,21,34,55
- FibonacciSequence(11): 0,1,1,2,3,5,8,13,21,34,55,89
- FibonacciSequence(12): 0,1,1,2,3,5,8,13,21,34,55,89,144
I try to improve my English language skills. Most things i do better than this.
- tisodotsk
- Apprentice

-

- Posts: 22
- Joined: Fri Aug 08, 2008 12:45 pm
- Location: Bratislava, Slovakia
13 posts • Page 1 of 1


LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.