Big Fib

Grevas
Posts: 10
Joined: Sat Oct 16, 2010 3:47 pm

Post by Grevas »

Just in case:

Fib(0) = 0
Fib(1) = 1
Fib(2) = 1
Fib(3) = 2

is currently used in this challenge. Just had a example in my python book about iterations using fibonacci sequence, so i modified it 'slightly' :) (~5min sounds about right, running it on one core only)
speedfire
Posts: 11
Joined: Sun Jul 29, 2012 1:10 am

Post by speedfire »

Oki finally I done it.

I have code a program with a logarithmic algorithme.

But for real... Do you really think everyone are mathematician ?

If you don't know anything about optimisation good luck ! You can wait a long long long time If you don't code proprely.
contagious
Posts: 35
Joined: Tue May 12, 2009 6:08 pm
Location: Greece

Post by contagious »

speedfire wrote:Oki finally I done it.

I have code a program with a logarithmic algorithme.

But for real... Do you really think everyone are mathematician ?

If you don't know anything about optimisation good luck ! You can wait a long long long time If you don't code proprely.
If you have struggled with this one, what will you do with "Biggest Fib"? :twisted:

Anyway you are on "hacker.org", this means you are supposed to tackle problems in a smart way.

Good luck!
gowron
Posts: 9
Joined: Mon Sep 20, 2010 2:23 pm

Why not use some tools?

Post by gowron »

Is using math software considered cheating? I was amazed how quickly maple calculated the fib number (using the closed-form solution, I guess).
AMindForeverVoyaging
Forum Admin
Posts: 496
Joined: Sat May 28, 2011 9:14 am
Location: Germany

Re: Why not use some tools?

Post by AMindForeverVoyaging »

gowron wrote:Is using math software considered cheating?
Of course not.
contagious
Posts: 35
Joined: Tue May 12, 2009 6:08 pm
Location: Greece

Re: Why not use some tools?

Post by contagious »

gowron wrote:Is using math software considered cheating? I was amazed how quickly maple calculated the fib number (using the closed-form solution, I guess).
Cheating? haha You are supposed to cheat if u can!
DEADD00D
Posts: 1
Joined: Mon Jul 14, 2014 8:36 am

Post by DEADD00D »

// F_1=1, F_2=1, F_n=F_{n-1}+F_{N-2};

// I tend to use Java.math.BigInteger when cope with big numbers, and it's handy.

import java.math.BigInteger;

public class Hacker144
{
private static final int INDEX = 1500000;
private static final int STEP = 20000;
public static void main(String args[])
{

BigInteger f1 = new BigInteger("1");
BigInteger f2 = new BigInteger("1");
for(long i = 1; i < INDEX; ++i)
{
BigInteger tmp = f2;
f2 = f2.add(f1);
f1 = tmp;
}

final String ans = f1.toString();
for(int i = 0; i < ans.length(); i += STEP)
System.out.print(ans.charAt(i));
}
}
/* Life runs on code */
Post Reply