Go to Post I may be a little slow responding, I'm shoveling snow. - Mark McLeod [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 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
  #2   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
  #3   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
  #4   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
  #5   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
  #6   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
  #7   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
  #8   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
  #9   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
  #10   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
  #11   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
  #12   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
  #13   Spotlight this post!  
Unread 23-06-2008, 22:42
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'll try to. I think I found a way to make my program significantly faster. With a new algorithm and my desktop computer it took ~9 sec to get the millionth term and 3:22:000 for the 5,000,000th. I'll try 100 mil. My guess is about 15-20 hour run time.
__________________
2053 Alumni

Reply With Quote
  #14   Spotlight this post!  
Unread 23-06-2008, 23:39
Ian Curtis Ian Curtis is offline
Best Available Data
FRC #1778 (Chill Out!)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Puget Sound
Posts: 2,520
Ian Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond repute
Re: Fibonacci Sequence

Quote:
Originally Posted by tennispro9911 View Post
I'll try to. I think I found a way to make my program significantly faster. With a new algorithm and my desktop computer it took ~9 sec to get the millionth term and 3:22:000 for the 5,000,000th. I'll try 100 mil. My guess is about 15-20 hour run time.
If you're going for speed, wouldn't it be a little bit faster to just use the explicit definition?
__________________
CHILL OUT! | Aero Stability & Control Engineer
Adam Savage's Obsessions (TED Talk) (Part 2)
It is much easier to call someone else a genius than admit to yourself that you are lazy. - Dave Gingery
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