LINUX.ORG.RU

История изменений

Исправление kto_tama, (текущая версия) :

Сорцы вы конечно же не предоставите.

лехко
гоу:

    a := big.NewInt(0)
    b := big.NewInt(1)
    var limit big.Int
    limit.Exp(big.NewInt(10), big.NewInt(20900), nil)
    for a.Cmp(&limit) < 0 {
        a.Add(a, b)
        a, b = b, a
    }

extern crate num;
use num::{BigUint, Zero, One};
use std::mem::replace;
extern crate time;
use time::PreciseTime;

// Calculate large fibonacci numbers.
fn fib(n: usize) -> BigUint {
    let mut f0: BigUint = Zero::zero();
    let mut f1: BigUint = One::one();
    for _ in 0..n {
        let f2 = f0 + &f1;
        // This is a low cost way of swapping f0 with f1 and f1 with f2.
        f0 = replace(&mut f1, f2);
    }
    f0
}

// This is a very large number.

fn main() {
    let start = PreciseTime::now();
    println!("fib(100000) = {}", fib(100000));
    let end = PreciseTime::now();
    println!("{} seconds ", start.to(end));
}


Исправление kto_tama, :

Сорцы вы конечно же не предоставите.

лехко
гоу:

    a := big.NewInt(0)
    b := big.NewInt(1)
    var limit big.Int
    limit.Exp(big.NewInt(10), big.NewInt(20900), nil)
    for a.Cmp(&limit) < 0 {
        a.Add(a, b)
        a, b = b, a
    }


раст:
[br]extern crate num;[br]use num::{BigUint, Zero, One};[br]use std::mem::replace;[br]extern crate time;[br]use time::PreciseTime;[br][br]// Calculate large fibonacci numbers.[br]fn fib(n: usize) -> BigUint {[br]    let mut f0: BigUint = Zero::zero();[br]    let mut f1: BigUint = One::one();[br]    for _ in 0..n {[br]        let f2 = f0 + &f1;[br]        // This is a low cost way of swapping f0 with f1 and f1 with f2.[br]        f0 = replace(&mut f1, f2);[br]    }[br]    f0[br]}[br][br]// This is a very large number.[br][br]fn main() {[br]    let start = PreciseTime::now();[br]    println!("fib(100000) = {}", fib(100000));[br]    let end = PreciseTime::now();[br]    println!("{} seconds ", start.to(end));[br]}[br]

Исходная версия kto_tama, :

Сорцы вы конечно же не предоставите.

лехко
гоу:

    a := big.NewInt(0)
    b := big.NewInt(1)
    var limit big.Int
    limit.Exp(big.NewInt(10), big.NewInt(20900), nil)
    for a.Cmp(&limit) < 0 {
        a.Add(a, b)
        a, b = b, a
    }


раст:
extern crate num;
use num::{BigUint, Zero, One};
use std::mem::replace;
extern crate time;
use time::PreciseTime;

// Calculate large fibonacci numbers.
fn fib(n: usize) -> BigUint {
    let mut f0: BigUint = Zero::zero();
    let mut f1: BigUint = One::one();
    for _ in 0..n {
        let f2 = f0 + &f1;
        // This is a low cost way of swapping f0 with f1 and f1 with f2.
        f0 = replace(&mut f1, f2);
    }
    f0
}

// This is a very large number.

fn main() {
    let start = PreciseTime::now();
    println!("fib(1000) = {}", fib(100000));
    let end = PreciseTime::now();
    println!("{} seconds ", start.to(end));
}