wu :: forums
« wu :: forums - Fibonacci Serious in reverse Order »

Welcome, Guest. Please Login or Register.
Dec 2nd, 2024, 4:05pm

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: Icarus, Eigenray, william wu, ThudnBlunder, SMQ, Grimbal, towr)
   Fibonacci Serious in reverse Order
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Fibonacci Serious in reverse Order  (Read 1983 times)
tuxilogy
Newbie
*





   


Posts: 45
Fibonacci Serious in reverse Order  
« on: Jun 10th, 2006, 3:41am »
Quote Quote Modify Modify

Hi can any one suggest me the algo regarding "Printing of the Fibonacci in reverse order "
Thanks in advance  
TUX
IP Logged
Barukh
Uberpuzzler
*****






   


Gender: male
Posts: 2276
Re: Fibonacci Serious in reverse Order  
« Reply #1 on: Jun 10th, 2006, 6:04am »
Quote Quote Modify Modify

What do you mean by "in reverse order"? Is a maximal element of the sequence given?
IP Logged
tuxilogy
Newbie
*





   


Posts: 45
Re: Fibonacci Serious in reverse Order  
« Reply #2 on: Jun 10th, 2006, 6:49am »
Quote Quote Modify Modify

1,1,2,3,5 is the Fibbonacci series for n = 5,  
 
reverse means given a number say n, one has to print  
 
the series in thsi was ----> " 5, 3, 2, 1,1"..
 
Tux
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: Fibonacci Serious in reverse Order  
« Reply #3 on: Jun 10th, 2006, 9:40am »
Quote Quote Modify Modify

I'd use recurrence
 
calculate the Kth fibonacci number (ideally, given the (K-1)th and (K-2)th ), call the function again for K+1 if K<N, print the Kth number.
 
But of course you could also use a stack.
IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
Grimbal
wu::riddles Moderator
Uberpuzzler
*****






   


Gender: male
Posts: 7527
Re: Fibonacci Serious in reverse Order  
« Reply #4 on: Jun 11th, 2006, 1:19pm »
Quote Quote Modify Modify

Recurence?? Stack??  Surely you're joking, Mr. Towr!
 
void fiborev(int n){
    int a=0, b=1;
    while( n-->0 ) a = (b+=a)-a;
    while( a ) printf(a?"%d,":"%d\n", b -= (a=b-a));
}
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: Fibonacci Serious in reverse Order  
« Reply #5 on: Jun 12th, 2006, 12:55am »
Quote Quote Modify Modify

Well sure, you could also do that, if you want to calculate each value twice...
 
Recurrence and stacks is a more general way to print things in reverse though..  So that's why it was the first thing that came to mind.  
You should see me print 1 to N in reverse Wink
IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
Grimbal
wu::riddles Moderator
Uberpuzzler
*****






   


Gender: male
Posts: 7527
Re: Fibonacci Serious in reverse Order  
« Reply #6 on: Jun 12th, 2006, 1:56am »
Quote Quote Modify Modify

on Jun 12th, 2006, 12:55am, towr wrote:
Well sure, you could also do that, if you want to calculate each value twice...

4 times actually.  I fixed that below.  Should be 4 times faster.
 
fiborev(int n){
  while( n-- )
    printf(n?"%.0lf,":"%.0lf\n", exp(log((sqrt(5)+1)/2)*(n+1))/sqrt(5));
}
on Jun 12th, 2006, 12:55am, towr wrote:
You should see me print 1 to N in reverse Wink

 
There are 2 schools:
   printf("N ot 1\n");
and
   printf("1 to N in reverse\n");
 
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: Fibonacci Serious in reverse Order  
« Reply #7 on: Jun 12th, 2006, 2:24am »
Quote Quote Modify Modify

on Jun 12th, 2006, 1:56am, Grimbal wrote:
There are 2 schools:
   printf("N ot 1\n");
and
   printf("1 to N in reverse\n");
Just two?
Why not
   printf("reve1 to Nrse\n");
?
IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
Grimbal
wu::riddles Moderator
Uberpuzzler
*****






   


Gender: male
Posts: 7527
Re: Fibonacci Serious in reverse Order  
« Reply #8 on: Jun 12th, 2006, 2:49am »
Quote Quote Modify Modify

Absolutely, a classical school.  How could I have missed that one?   Grin
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board