Go to Post What's the point of competing if you're not going to be competitive? - davepowers [more]
Home
Go Back   Chief Delphi > Other > Math and Science
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 22-06-2008, 23:36
ComradeNikolai ComradeNikolai is offline
Registered User
AKA: Nicholas
FRC #2603 (Team Hornet)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2008
Location: Medina, Ohio
Posts: 203
ComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to behold
Fibonacci Sequence

Well, suffice it to say I was bored, so I wrote a little (5 line) python program to calculate terms of the Fibonacci sequence.

The 1001th term is:
70330367711422815821835254877183549770181269836358 73274260490508715453711819693357974224949456261173 34877504492417659910881863632654502236471060120533 74121273867339111198139373125598767690091902245245 323403501

It's still computing the 1000 000th term or I'd have that for you, too. It has 110 000 terms to go.
__________________
I cut myself shaving with Occam's razor.


Last edited by ComradeNikolai : 23-06-2008 at 08:10. Reason: 1001th, not 1000th
Reply With Quote
  #2   Spotlight this post!  
Unread 23-06-2008, 00:17
tennispro9911 tennispro9911 is offline
Alumni
AKA: Matt
FRC #2053 (TigerTronics)
Team Role: Alumni
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Endicott
Posts: 86
tennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to behold
Send a message via AIM to tennispro9911
Re: Fibonacci Sequence

I believe that is the 1001th term, not the 1000th term.

The 1000th term is 43466557686937456435688527675040625802564660517371 78040248172908953655541794905189040387984007925516 92959225930803226347752096896232398733224711616429 96440906533187938298969649928516003704476137795166 849228875.
__________________
2053 Alumni

Reply With Quote
  #3   Spotlight this post!  
Unread 23-06-2008, 02:12
whitetiger0990's Avatar
whitetiger0990 whitetiger0990 is offline
Registered User
no team
Team Role: Programmer
 
Join Date: Mar 2006
Rookie Year: 2006
Location: Earth
Posts: 157
whitetiger0990 is a glorious beacon of lightwhitetiger0990 is a glorious beacon of lightwhitetiger0990 is a glorious beacon of lightwhitetiger0990 is a glorious beacon of lightwhitetiger0990 is a glorious beacon of light
Re: Fibonacci Sequence

Can your 5 lines of python beat my 3 lines of perl? =P

Code:
use bignum;
$b=1;
$x++,($a,$b)=($b,$a+$b),print"$x|$a\n"while(1);
And tennispro9911 is right, I think you forgot that the first two numbers in the series is '1'.

Can we see your program? =]

(I like perl *glances at his signature =D*)
__________________
print$q=chr(ord($q)+$1)while("7443-0201-8465130105-12-03135-82482113-06-7672-070208-0613-70"=~/(-?\d\d)/g);
Reply With Quote
  #4   Spotlight this post!  
Unread 23-06-2008, 08:09
ComradeNikolai ComradeNikolai is offline
Registered User
AKA: Nicholas
FRC #2603 (Team Hornet)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2008
Location: Medina, Ohio
Posts: 203
ComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to behold
Re: Fibonacci Sequence

Oh, yeah, my bad; it is the 1001th term. That makes the one my computer chugged all night for the million and first term, and it was bigger than the gnome terminal can display ... so I don't have it.

Here's the program, as requested
Code:
#! /usr/bin/python
a,b,c = 0,1,1000
while c > 0:
	a,b,c = b, a+b, c-1
print b
c could be modified to get any given term, adjusting for the first term already being calculated. I'm not sure if there's a more efficient way of doing this in Python, just started learning it.

Perl impresses me.
__________________
I cut myself shaving with Occam's razor.

Reply With Quote
  #5   Spotlight this post!  
Unread 23-06-2008, 11:24
EricVanWyk EricVanWyk is offline
Registered User
no team
 
Join Date: Jan 2007
Rookie Year: 2000
Location: Boston
Posts: 1,597
EricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond repute
Send a message via AIM to EricVanWyk
Re: Fibonacci Sequence

Python can do it in 1:

Code:
for z in range(N-1): print vars().setdefault('a',[1,1]) and a.append(a.pop(0)+a[0]) or a[0][0]
Stolen shamelessly from Bengt Richter. Put your term in place of N.

That being shown, this is the antithesis of the language and good coding practice. As one who has had to work with tools coded in Perl, all I will say is that obfuscation isn't nearly as cool as perlers think it is. I'd rather work with something written in a hundred lines of python than in 5 lines of perl.
Reply With Quote
  #6   Spotlight this post!  
Unread 23-06-2008, 15:06
tennispro9911 tennispro9911 is offline
Alumni
AKA: Matt
FRC #2053 (TigerTronics)
Team Role: Alumni
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Endicott
Posts: 86
tennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to behold
Send a message via AIM to tennispro9911
Re: Fibonacci Sequence

I did it in java, because thats what I use regularly, along with Easy C for FIRST. I think though I can write a program that can find the millionth term that runs in only a couple minutes. I'll test it out later.

I also need to output to a file instead of a screen.
__________________
2053 Alumni


Last edited by tennispro9911 : 23-06-2008 at 15:08.
Reply With Quote
  #7   Spotlight this post!  
Unread 23-06-2008, 15:55
ComradeNikolai ComradeNikolai is offline
Registered User
AKA: Nicholas
FRC #2603 (Team Hornet)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2008
Location: Medina, Ohio
Posts: 203
ComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to behold
Re: Fibonacci Sequence

Mine probably could run in less than hours or a few minutes, but I had a horribly bad computer which I was using it; Windows 98 lags the computer, so it's running Ubuntu.
__________________
I cut myself shaving with Occam's razor.

Reply With Quote
  #8   Spotlight this post!  
Unread 23-06-2008, 16:52
tennispro9911 tennispro9911 is offline
Alumni
AKA: Matt
FRC #2053 (TigerTronics)
Team Role: Alumni
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Endicott
Posts: 86
tennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to behold
Send a message via AIM to tennispro9911
Re: Fibonacci Sequence

The millionth term is way too long to display. I tried, took up a couple thousand lines on my browser. I also can't include a file in the post because the limit for a txt file is 100 kb and my file is 204.1 kb. For anyone who wants to check if their program works correctly, the first few digits are 195328212870775773163201494759625.....

It took me 0:29:843 (min:sec:millis) to calculate it, and 1:21:467 total to calculate it and output it to a file. The number is so fricken large it took longer to write it to a file. How often can you say that?
__________________
2053 Alumni


Last edited by tennispro9911 : 23-06-2008 at 16:59. Reason: Removed number
Reply With Quote
  #9   Spotlight this post!  
Unread 23-06-2008, 17:16
tennispro9911 tennispro9911 is offline
Alumni
AKA: Matt
FRC #2053 (TigerTronics)
Team Role: Alumni
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Endicott
Posts: 86
tennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to behold
Send a message via AIM to tennispro9911
Re: Fibonacci Sequence

So I changed my program to break up the files to about 90 kb each file. Here are my files. First one contains first x digits and so on and so forth. 90k digits in the first two files.
Attached Files
File Type: txt fib1.txt (87.9 KB, 48 views)
File Type: txt fib2.txt (87.9 KB, 44 views)
File Type: txt fib3.txt (28.3 KB, 36 views)
__________________
2053 Alumni


Last edited by tennispro9911 : 23-06-2008 at 17:17. Reason: Explaining files
Reply With Quote
  #10   Spotlight this post!  
Unread 23-06-2008, 18:03
ComradeNikolai ComradeNikolai is offline
Registered User
AKA: Nicholas
FRC #2603 (Team Hornet)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2008
Location: Medina, Ohio
Posts: 203
ComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to behold
Re: Fibonacci Sequence

What language did you use for that? I would try it in C++, but I know that C++ has roundoff due to not allowing such large numbers...
__________________
I cut myself shaving with Occam's razor.

Reply With Quote
  #11   Spotlight this post!  
Unread 23-06-2008, 18:08
tennispro9911 tennispro9911 is offline
Alumni
AKA: Matt
FRC #2053 (TigerTronics)
Team Role: Alumni
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Endicott
Posts: 86
tennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to behold
Send a message via AIM to tennispro9911
Re: Fibonacci Sequence

A bad computer slows it down by a linear multiplier. Say if my computer is 2.0 Ghz and your computer is 200 MHz then it would take your comp about 10 times longer to run the same program, depending on things running in the background. I doubt your computer is slower than 200 MHz, so if it takes a whole night to run, then it would still take an hour or so to run on a "fast" computer. That said, obviously if you don't calculate every term in between, you can calculate the nth term much much faster, which is why I could calculate the millionth in 29 sec instead of a few hours.
__________________
2053 Alumni

Reply With Quote
  #12   Spotlight this post!  
Unread 23-06-2008, 18:09
tennispro9911 tennispro9911 is offline
Alumni
AKA: Matt
FRC #2053 (TigerTronics)
Team Role: Alumni
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Endicott
Posts: 86
tennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to behold
Send a message via AIM to tennispro9911
Re: Fibonacci Sequence

I used Java. I used the BigInteger class. Otherwise I would have roundoff errors as you said.
__________________
2053 Alumni

Reply With Quote
  #13   Spotlight this post!  
Unread 23-06-2008, 18:45
ComradeNikolai ComradeNikolai is offline
Registered User
AKA: Nicholas
FRC #2603 (Team Hornet)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2008
Location: Medina, Ohio
Posts: 203
ComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to behold
Re: Fibonacci Sequence

Ah, yes, Java. I should learn that sometime... after I finish learning C++ and learn Python. Maybe if I hook myself up with the AP CS exam next year, I'll be motivated enough to learn Java (our school doesn't offer AP CS, but I was able to take AP English without the class this year, so I don't see a difference there).

What kind of hardware do you have on the computer you did that on?
Oh, just FYI, I think the computer I did this on originally has 256 MB RAM and less than a 1 GHz processor... not fun...
__________________
I cut myself shaving with Occam's razor.

Reply With Quote
  #14   Spotlight this post!  
Unread 23-06-2008, 18:53
tennispro9911 tennispro9911 is offline
Alumni
AKA: Matt
FRC #2053 (TigerTronics)
Team Role: Alumni
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Endicott
Posts: 86
tennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to beholdtennispro9911 is a splendid one to behold
Send a message via AIM to tennispro9911
Re: Fibonacci Sequence

I'm on a Lenovo laptop right not. T40. 1 GB RAM, 1.59 GHz processor. So its not the latest and greatest, but at the same time it works well, and faster than your machine. My home desktop is better. I'm going to run it on that and see what happens. For kicks I'd see how high I can get. I got to the 10,000,000th term in about 37 minutes, and I'm guessing it would take around 50 hours to get to 100,000,000 if the pattern continues.
__________________
2053 Alumni

Reply With Quote
  #15   Spotlight this post!  
Unread 23-06-2008, 20:34
ComradeNikolai ComradeNikolai is offline
Registered User
AKA: Nicholas
FRC #2603 (Team Hornet)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2008
Location: Medina, Ohio
Posts: 203
ComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to beholdComradeNikolai is a splendid one to behold
Re: Fibonacci Sequence

Try the 100 000 000 and post the results... THAT would take a lot of text documents.
__________________
I cut myself shaving with Occam's razor.

Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mechanics of a 3 speed shifting sequence sanddrag Technical Discussion 3 27-02-2005 00:34
[FVG]: Opening Sequence Joshua May FIRST-related Organizations 16 24-06-2004 00:00
RC bootup sequence Venkatesh Programming 17 18-11-2003 20:56
PB_Mode Sequence DKolberg Programming 3 17-03-2003 10:54
Competition Sequence for PBasic ttedrow Programming 12 23-01-2003 08:49


All times are GMT -5. The time now is 07:50.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi