Фибоначи

Краен срок
14.10.2020 17:00
Точки
2

Срокът за предаване на решения е отминал

Целта на това първо предизвикателство е да имплементирате функция, която връща поредното число от редицата на фибоначи, с първи индекс 0. Тоест,

  • С вход 0, функцията се очаква да върне 1
  • С вход 1, функцията се очаква да върне 1
  • С какъвто и да е друг вход, функцията връща сумата на предните две числа на фибоначи.

Заместете todo!() със своята имплементация на тази функция:

pub fn fib(n: u32) -> u32 {
    todo!()
}

Решения

Андрей
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Андрей

pub fn fib(n: u32) -> u32 {
if n <= 1 {
1
} else {
fib(n - 1) + fib(n - 2)
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-178ajv7/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.70s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Йордан Миронски
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Йордан Миронски

pub fn fib(n: u32) -> u32 {
if n <= 1 {return 1;}
fib(n - 1) + fib(n - 2)
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-rnm61x/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.07s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Тервел Вълков
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Тервел Вълков

pub fn fib(n: u32) -> u32 {
if n == 0 || n == 1 {
return 1;
}
fib(n - 1) + fib(n - 2)
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-e2v4s8/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.10s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Илиян Йорданов
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Илиян Йорданов

pub fn fib(n: u32) -> u32 {
let (mut a, mut b, mut c, mut i) = (1u32, 1u32, 1u32, 1u32);
while i<n {
c=a+b;
a=b;
b=c;
i+=1;
}
c
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-zgoau2/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.01s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Теодор Тошков
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Теодор Тошков

pub fn fib(n: u32) -> u32 {
let mut a = 1;
let mut b = 1;
for _i in 0..n {
let temp = a;
a = b;
b = b + temp;
}
a
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-1fah8ri/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.16s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Пламен Николов
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Пламен Николов

pub fn fib(n: u32) -> u32 {
if n == 0 {
return 1;
}
if n == 1 {
return 1;
}
fib(n - 1) + fib(n - 2)
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-a26ked/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.30s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Борислав Димитров
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Борислав Димитров

pub fn fib(n: u32) -> u32 {
/* за нубари
if n==0 {
1
} else if n==1 {
1
} else {
fib(n-1)+fib(n-2)
}*/
let mut x0 = 1;
let mut x1 = 1;
let mut i = 0;
while i < n {
if i%2 == 0 {
x0 = x0 + x1;
} else {
x1 = x0 + x1;
}
i += 1;
}
if n%2 == 0{
x0
} else {
x1
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-j2c4e/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.40s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Тодор Димов
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Тодор Димов

pub fn fib(n: u32) -> u32
{
let mut counter = n;
// fib(0) should be 0
let mut a = 1_u32;
let mut b = 1_u32;
while counter > 0
{
let temp = a;
a = b;
b = temp + a;
counter = counter - 1;
}
a
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-ci9f9n/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.14s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Бетина Христова
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Бетина Христова

pub fn fib(n: u32) -> u32 {
let mut tup: (u32, u32, u32) = (0,1,1);
let mut cnt = 0;
while cnt <= n {
let sum = tup.1 + tup.2;
tup.0 = tup.1;
tup.1 = tup.2;
tup.2 = sum;
cnt += 1;
}
tup.0
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-10eyz05/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.06s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Иван Лучев
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Лучев

pub fn fib(n: u32) -> u32 {
let mut minus1 = 0;
let mut current = 1;
for _ in 1..=n {
let next = minus1 + current;
minus1 = current;
current = next;
}
current
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-1t6xiwa/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.09s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Биляна Йорданова
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Биляна Йорданова

pub fn fib(n: u32) -> u32 {
if n == 0 || n == 1
{
1
}
else
{
let mut prev: u32 = 1;
let mut result: u32 = 1;
let mut n = n;
while n != 1
{
result += prev;
prev = result - prev;
n -= 1;
}
result
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-1bq4z6n/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.03s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Стефан Ангелов
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Стефан Ангелов

pub fn fib(n: u32) -> u32 {
if n == 0 || n == 1 {
return 1;
}
else {
return fib(n - 1) + fib(n - 2);
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-gjne27/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.02s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Николай Петков
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Петков

pub fn fib(n: u32) -> u32 {
if n == 0 || n == 1 {
1
} else {
fib(n - 1) + fib(n - 2)
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-n87yp3/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.77s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Гергана Тончева
  • Некоректно
  • 0 успешни тест(а)
  • 1 неуспешни тест(а)
Гергана Тончева

/*
================================================================================
Title: Fibonacci numbers
Author: Gergana Toncheva
Date: 08 Oct 2020
================================================================================
*/
/*
----The function calculates the n-th Fibonacci number using for loop
previous: previous number in Fibonacci sequence
current: current number in Fibonacci sequence
temp: contains the current number in the sequence
until the next number is calculated
----Example:
input: 0 1 2 3 4 5 6...
output: 1 1 2 3 5 8 13...
*/
pub fn fib(n: u32) -> u32 {
let mut previous: u32 = 1;
let mut current: u32 = 1;
for _i in 0..(n-1) {
let temp = current;
current = current + previous;
previous = temp;
}
current
}
/*
----The function calculates the n-th Fibonacci number using recursion
----Example:
input: 0 1 2 3 4 5 6...
output: 1 1 2 3 5 8 13...
*/
pub fn fib2(n: u32) -> u32 {
if n <= 1 {
return 1;
}
fib2(n - 1) + fib2(n - 2)
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-yjt89/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.73s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... FAILED

failures:

---- solution_test::test_full stdout ----
thread 'main' panicked at 'attempt to subtract with overflow', src/lib.rs:23:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    solution_test::test_full

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--test solution_test'
Стайко Дафов
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Стайко Дафов

pub fn fib(n: u32) -> u32 {
if n <= 1 {
return 1;
}
fib(n - 1) + fib(n -2)
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-n4r190/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.02s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Йоана Зелова
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Йоана Зелова

pub fn fib(n: u32) -> u32 {
if n == 0 {
1
} else if n == 1 {
1
} else {
fib(n-1) + fib(n-2)
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-zjfgiu/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.05s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Владислав Георгиев
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Владислав Георгиев

pub fn fib(n: u32) -> u32 {
if n == 0 || n == 1 {
return 1;
}
return fib(n-1) + fib(n-2);
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-u1jy65/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.11s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Богомила Петрова
  • Некоректно
  • 0 успешни тест(а)
  • 1 неуспешни тест(а)
Богомила Петрова

pub fn fib(n: u32) -> u32 {
let mut first : u32 = 1;
let mut second : u32 = 1;
let mut mid : u32 = 2;
let mut indx : u32 = 1;
if n == 0 || n == 1 {
return 1;
}
loop {
if indx == n-1 {
return mid;
}
mid = first + second;
first = second;
second = mid;
indx += 1;
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-1x629vv/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.13s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... FAILED

failures:

---- solution_test::test_full stdout ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `2`,
 right: `3`', tests/solution_test.rs:11:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    solution_test::test_full

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--test solution_test'
Юмит Яйя
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Юмит Яйя

pub fn fib(n: u32) -> u32 {
if n < 2{
return 1;
}
let mut counter = 1_u32;
let mut current_fib:[u32; 2] = [1,1];
while counter < n {
counter += 1;
current_fib[{counter%2} as usize] = current_fib[0] + current_fib[1];
}
return current_fib[{counter%2} as usize];
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-1do3oli/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.38s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Радослав Хубенов
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Радослав Хубенов

pub fn fib(n: u32) -> u32 {
if n == 0 {
return 1;
} else if n == 1 {
return 1;
} else {
return fib(n - 1) + fib(n - 2);
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-1dt3w6c/solution)
    Finished test [unoptimized + debuginfo] target(s) in 0.99s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Николай Георгиев
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Георгиев

pub fn fib(n: u32) -> u32 {
let mut x: u32 = 1;
let mut sum: u32 = 1;
let mut count = 2;
if n == 0 || n == 1{
return 1;
}else{
while count <= n{
sum += x;
x = sum - x;
count += 1;
}
sum
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-1bqe6pk/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.12s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Александър Димитров
  • Некоректно
  • 0 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Димитров

fn main() {
println!( "index:\trec\tlin" );
for i in 0..MAX_FIB_COUNT {
println!( "{0}:\t{1}\t{2}", i, fib_rec( i ), fib_lin( i ) );
}
}
const MAX_FIB_COUNT: usize = 186;
pub fn fib_rec( index: usize ) -> u128 {
static mut FIB_ARR: [ u128; MAX_FIB_COUNT ] = {
let mut arr: [ u128; MAX_FIB_COUNT ] = [ 0; MAX_FIB_COUNT ];
arr[ 0 ] = 1;
arr[ 1 ] = 1;
arr
};
unsafe { // static is considered unsafe in Rust? :O
if FIB_ARR[ index ] == 0 {
FIB_ARR[ index ] = fib_rec( index - 1 ) + fib_rec( index - 2 );
}
FIB_ARR[ index ]
}
}
pub fn fib_lin( mut index: usize ) -> u128 {
let mut previous = 0u128;
let mut result = 1u128;
while index > 0 { // for ( ; index > 0; --index) pls.. :D
std::mem::swap( &mut previous, &mut result );
result += previous;
index -= 1;
}
result
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-6dt022/solution)
warning: function is never used: `main`
 --> src/lib.rs:1:4
  |
1 | fn main() {
  |    ^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

error[E0425]: cannot find function `fib` in this scope
 --> tests/solution_test.rs:8:16
  |
8 |     assert_eq!(fib(0), 1);
  |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
 --> tests/solution_test.rs:9:16
  |
9 |     assert_eq!(fib(1), 1);
  |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:10:16
   |
10 |     assert_eq!(fib(2), 1 + 1);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:11:16
   |
11 |     assert_eq!(fib(3), 1 + 2);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:12:16
   |
12 |     assert_eq!(fib(4), 2 + 3);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:13:16
   |
13 |     assert_eq!(fib(5), 3 + 5);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:14:16
   |
14 |     assert_eq!(fib(6), 5 + 8);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:15:16
   |
15 |     assert_eq!(fib(7), 8 + 13);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:16:16
   |
16 |     assert_eq!(fib(8), 13 + 21);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:17:16
   |
17 |     assert_eq!(fib(9), 21 + 34);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:18:16
   |
18 |     assert_eq!(fib(10), 34 + 55);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:19:16
   |
19 |     assert_eq!(fib(11), 55 + 89);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:20:16
   |
20 |     assert_eq!(fib(12), 89 + 144);
   |                ^^^ not found in this scope

warning: unused import: `solution::*`
 --> tests/solution_test.rs:4:7
  |
4 |   use solution::*;
  |       ^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error: aborting due to 13 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0425`.
error: could not compile `solution`.

To learn more, run the command again with --verbose.
Роман Слугин
  • Некоректно
  • 0 успешни тест(а)
  • 0 неуспешни тест(а)
Роман Слугин

fn main() {
use std::io::{stdin,stdout,Write};
let mut string = String::new();
print!("Please enter some number: ");
let _=stdout().flush();
stdin().read_line(&mut string).expect("Did not enter a correct number");
let trimmed = string.trim();
match trimmed.parse::<u32>() {
Ok(number) => println!("Thanks for proper input: {}, now we will make Fibonacci sequence", number),
Err(..) => println!("Wrong input, please enter a number: {}", trimmed)
};
let start: u32 = 0;
let mut number: u32 = trimmed.parse::<u32>().unwrap();
number += 1;
let mut result: u32 = 0;
for n in start..number+1 {
result = fib(n);
}
println!("result = {}", result);
}
fn fib(number: u32) -> u32 {
if number == 0 {
return number;
}
if number == 1 {
return number;
}
fib(number-1) + fib(number-2)
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-1clgapg/solution)
warning: function is never used: `main`
 --> src/lib.rs:1:4
  |
1 | fn main() {
  |    ^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: function is never used: `fib`
  --> src/lib.rs:27:4
   |
27 | fn fib(number: u32) -> u32 {
   |    ^^^

warning: 2 warnings emitted

error[E0425]: cannot find function `fib` in this scope
 --> tests/solution_test.rs:8:16
  |
8 |     assert_eq!(fib(0), 1);
  |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
 --> tests/solution_test.rs:9:16
  |
9 |     assert_eq!(fib(1), 1);
  |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:10:16
   |
10 |     assert_eq!(fib(2), 1 + 1);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:11:16
   |
11 |     assert_eq!(fib(3), 1 + 2);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:12:16
   |
12 |     assert_eq!(fib(4), 2 + 3);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:13:16
   |
13 |     assert_eq!(fib(5), 3 + 5);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:14:16
   |
14 |     assert_eq!(fib(6), 5 + 8);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:15:16
   |
15 |     assert_eq!(fib(7), 8 + 13);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:16:16
   |
16 |     assert_eq!(fib(8), 13 + 21);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:17:16
   |
17 |     assert_eq!(fib(9), 21 + 34);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:18:16
   |
18 |     assert_eq!(fib(10), 34 + 55);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:19:16
   |
19 |     assert_eq!(fib(11), 55 + 89);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:20:16
   |
20 |     assert_eq!(fib(12), 89 + 144);
   |                ^^^ not found in this scope

warning: unused import: `solution::*`
 --> tests/solution_test.rs:4:7
  |
4 |   use solution::*;
  |       ^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error: aborting due to 13 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0425`.
error: could not compile `solution`.

To learn more, run the command again with --verbose.
Даниел Стоянов
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Даниел Стоянов

pub fn fib(n: u32) -> u32 {
let mut first: u32 = 1;
let mut second: u32 = 1;
// not checking n < 0 because n is u32
if n == 0 || n == 1 {
return first;
} else {
for _i in 1..n {
let temp: u32 = second;
second += first;
first = temp;
}
}
second
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-ggabpf/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.20s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Костадин Пеков
  • Некоректно
  • 0 успешни тест(а)
  • 1 неуспешни тест(а)
Костадин Пеков

pub fn fib(n: u32) -> u32 {
if n <= 1
{
return n;
}
fib(n - 1) + fib(n - 2)
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-1gbgssx/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.25s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... FAILED

failures:

---- solution_test::test_full stdout ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `0`,
 right: `1`', tests/solution_test.rs:8:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    solution_test::test_full

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--test solution_test'
Симеон Николов
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Симеон Николов

pub fn fib(n: u32) -> u32 {
if n == 0 {
1
}
else if n == 1{
1
}
else {
fib(n-1) + fib(n-2)
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-77ft93/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.08s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Християна Панайотова
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Християна Панайотова

pub fn fib(n: u32) -> u32 {
if n == 1 || n == 0 {
1
} else {
fib(n - 1) + fib(n - 2)
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-1nxbc27/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.29s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Ивайло Иванов
  • Некоректно
  • 0 успешни тест(а)
  • 1 неуспешни тест(а)
Ивайло Иванов

pub fn fib(n: u32) -> u32 {
if n == 0{
1
} else if n == 1{
1
}
else{
let mut current = 0;
let mut prev = 1;
let mut prev2 = 0;
for _i in 1..n{
current = prev + prev2;
prev2 = prev;
prev = current;
}
current
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-1ne74xv/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.61s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... FAILED

failures:

---- solution_test::test_full stdout ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `2`', tests/solution_test.rs:10:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    solution_test::test_full

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--test solution_test'
Ана Стоянова
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Ана Стоянова

pub fn fib(n: u32) -> u32 {
if n == 0 {
return 1;
}
if n == 1 {
return 1;
}
else {
return fib(n-1) + fib(n-2);
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-s789os/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.71s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Илиян Руйков
  • Некоректно
  • 0 успешни тест(а)
  • 1 неуспешни тест(а)
Илиян Руйков

pub fn fib(n: u32) -> u32 {
let mut current = 0;
let mut next = 1;
let mut counter = 0;
loop{
let temp = current + next;
current = next;
next = temp;
counter += 1;
if counter == n {
break;
}
}
current
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-my3kqn/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.01s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... FAILED

failures:

---- solution_test::test_full stdout ----
thread 'main' panicked at 'attempt to add with overflow', src/lib.rs:6:20
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    solution_test::test_full

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--test solution_test'
Станислав Жечев
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Станислав Жечев

pub fn fib(n: u32) -> u32 {
if n <= 1 {
return 1;
} else {
return fib(n - 1) + fib(n - 2);
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-ghas4x/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.00s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Мартин Тодоров
  • Некоректно
  • 0 успешни тест(а)
  • 1 неуспешни тест(а)
Мартин Тодоров

pub fn fib(n: u32) -> u32 {
if n == 1 || n == 0 {
return n
}
fib(n-1) + fib(n-2)
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-18sn1jc/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.29s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... FAILED

failures:

---- solution_test::test_full stdout ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `0`,
 right: `1`', tests/solution_test.rs:8:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    solution_test::test_full

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--test solution_test'
Лили Стефанова
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Лили Стефанова

pub fn fib(n: u32) -> u32 {
let mut counter : u32 = 2;
let mut fib_prev = 1;
let mut fib_current = 1;
let mut fib_new;
loop
{
if n == 0 {break 1;}
if n == 1 {break 1;}
fib_new = fib_prev + fib_current;
fib_prev = fib_current;
fib_current = fib_new;
if counter == n {break fib_new;}
counter += 1;
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-h6zkrt/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.16s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Мартин Великов
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Мартин Великов

pub fn fib(n: u32) -> u32 {
if n < 2 {
1
} else {
fib(n-1) + fib(n-2)
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-10p58hf/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.06s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Антонина Ускова
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Антонина Ускова

pub fn fib(n: u32) -> u32 {
if n == 0 || n == 1 {
1
}
else {
let mut current_index: u32 = 2;
let mut last_num: u32 = 1;
let mut second_last_num: u32 = 1;
// It always will be that index till u32::MAX remains the same.
let max_fibonacci_index = 47;
while current_index <= n {
if current_index >= max_fibonacci_index {
println!("{}-th Fibonacci number is greater than u32::MAX: {}.", n, u32::MAX);
}
last_num = last_num + second_last_num;
second_last_num = last_num - second_last_num;
current_index += 1;
}
last_num
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-k1pmwz/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.10s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Ева Николова
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Ева Николова

pub fn fib(n: u32) -> u32 {
if n < 2 {
1
} else {
fib(n - 1) + fib(n - 2)
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-oohos2/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.28s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Петър Янакиев
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Янакиев

pub fn fib(n: u32) -> u32 {
if n == 0 || n == 1 {
return 1
}
fib(n - 1) + fib(n - 2)
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-7rqelw/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.36s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Милко Кунев
  • Некоректно
  • 0 успешни тест(а)
  • 1 неуспешни тест(а)
Милко Кунев

pub fn fib(n: u32) -> u32 {
if n == 0 || n == 1 {
1
} else {
_fib(0, 1, n)
}
}
pub fn _fib(left: u32, right: u32, n: u32) -> u32 {
if n == 1 {
right
} else {
_fib(right, left + right, n - 1)
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-186k8m7/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.96s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... FAILED

failures:

---- solution_test::test_full stdout ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `2`', tests/solution_test.rs:10:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    solution_test::test_full

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--test solution_test'
Лъчезар Младенов
  • Некоректно
  • 0 успешни тест(а)
  • 0 неуспешни тест(а)
Лъчезар Младенов

fn fib(n: u32) -> u32 {
if n <= 1 {
return 1
}
// fib(n - 1) + fib(n - 2)
let mut fst: u32 = 1;
let mut snd: u32 = 1;
let mut result: u32 = fst + snd;
let mut i:u32 = 2;
while i != n {
fst = snd;
snd = result;
result = fst + snd;
i += 1;
}
result
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-119t3g5/solution)
warning: function is never used: `fib`
 --> src/lib.rs:1:4
  |
1 | fn fib(n: u32) -> u32 {
  |    ^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

warning: function is never used: `fib`
 --> src/lib.rs:1:4
  |
1 | fn fib(n: u32) -> u32 {
  |    ^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

error[E0425]: cannot find function `fib` in this scope
 --> tests/solution_test.rs:8:16
  |
8 |     assert_eq!(fib(0), 1);
  |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
 --> tests/solution_test.rs:9:16
  |
9 |     assert_eq!(fib(1), 1);
  |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:10:16
   |
10 |     assert_eq!(fib(2), 1 + 1);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:11:16
   |
11 |     assert_eq!(fib(3), 1 + 2);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:12:16
   |
12 |     assert_eq!(fib(4), 2 + 3);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:13:16
   |
13 |     assert_eq!(fib(5), 3 + 5);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:14:16
   |
14 |     assert_eq!(fib(6), 5 + 8);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:15:16
   |
15 |     assert_eq!(fib(7), 8 + 13);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:16:16
   |
16 |     assert_eq!(fib(8), 13 + 21);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:17:16
   |
17 |     assert_eq!(fib(9), 21 + 34);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:18:16
   |
18 |     assert_eq!(fib(10), 34 + 55);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:19:16
   |
19 |     assert_eq!(fib(11), 55 + 89);
   |                ^^^ not found in this scope

error[E0425]: cannot find function `fib` in this scope
  --> tests/solution_test.rs:20:16
   |
20 |     assert_eq!(fib(12), 89 + 144);
   |                ^^^ not found in this scope

warning: unused import: `solution::*`
 --> tests/solution_test.rs:4:7
  |
4 |   use solution::*;
  |       ^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error: aborting due to 13 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0425`.
error: could not compile `solution`.

To learn more, run the command again with --verbose.
Мартин Дацев
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Мартин Дацев

pub fn fib(n: u32) -> u32 {
match n {
0 => 1,
1 => 1,
_ => fib(n - 1) + fib(n - 2)
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-g3zcsb/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.08s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Ралица Добрева
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Ралица Добрева

pub fn fib(n: u32) -> u32 {
let mut f1 = 1u32;
let mut f2 = 1u32;
let mut f = 0u32;
if n == 0 || n == 1 {
f1
} else {
for _i in 1..n {
f = f1 + f2;
f1 = f2;
f2 = f;
}
f
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-g03vaq/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.11s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Васил Папукчиев
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Васил Папукчиев

pub fn fib(n: u32) -> u32 {
if n <= 1 {
return 1;
}
let fibonacci_number = fib(n - 1) + fib(n - 2);
fibonacci_number
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-b4kb2g/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.53s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Велин Клисуров
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Велин Клисуров

pub fn fib(n: u32) -> u32 {
let mut x = 1;
let mut y = 1;
for _i in 0..n {
let tmp = x + y;
x = y;
y = tmp;
}
x
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-1ay8fky/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.10s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Иван Камбуров
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Камбуров

pub fn fib(n: u32) -> u32 {
let mut fibs: (u32, u32) = (1, 1);
for _ in 2..n+1 {
fibs = (fibs.1, fibs.0 + fibs.1)
}
fibs.1
}
// pub fn fib_iter(n: u32) -> u32 {
// if n < 2 {
// return 1;
// }
// let mut prev: u32 = 1;
// let mut last: u32 = 2;
// for _ in 3..n+1 {
// let curr = prev + last;
// prev = last;
// last = curr;
// }
// last
// }
// pub fn fib_iter_tuple(n: u32) -> u32 {
// let mut fibs: (u32, u32) = (1, 1);
// for _ in 2..n+1 {
// fibs = (fibs.1, fibs.0 + fibs.1)
// }
// fibs.1
// }
// pub fn fib_rec(n: u32) -> u32 {
// if n < 2 {
// return 1;
// }
// fib_rec(n - 1) + fib_rec(n-2)
// }
// fn fib_match(n: u32) -> u32 {
// match n {
// 0 => 1,
// 1 => 1,
// _ => fib_match(n - 1) + fib_match(n - 2),
// }
// }
// fn main() {
// for n in 0..15/*42*/ {
// println!("fib_rec({:?}) = {:?}", n, fib_rec(n));
// println!("fib_match({:?}) = {:?}", n, fib_match(n));
// println!("fib_iter({:?}) = {:?}", n, fib_iter(n));
// println!("fib_iter_tuple({:?}) = {:?}", n, fib_iter_tuple(n));
// }
// }
Compiling solution v0.1.0 (/tmp/d20201014-2816268-7ctirv/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.08s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Сашо Михайлов
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Сашо Михайлов

pub fn fib(n: u32) -> u32 {
let mut a0: u32 = 0;
let mut a1: u32 = 1;
let mut i: u32 = 0;
while i < n {
let tmp = a0 + a1;
a0 = a1;
a1 = tmp;
i+=1;
}
a1
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-1fdibcl/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.01s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Йоана Николова
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Йоана Николова

pub fn fib(n: u32) -> u32 {
if n == 0 { return 1 };
if n == 1 { return 1 };
return fib(n - 1) + fib(n - 2);
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-jc6ey/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.03s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Жечко Попов
  • Некоректно
  • 0 успешни тест(а)
  • 1 неуспешни тест(а)
Жечко Попов

pub fn fib(n : u32) -> u32 {
if n == 0 {
0u32
} else if n == 1 {
1u32
} else {
fib(n - 1) + fib(n - 2)
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-5uoru8/solution)
    Finished test [unoptimized + debuginfo] target(s) in 0.99s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... FAILED

failures:

---- solution_test::test_full stdout ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `0`,
 right: `1`', tests/solution_test.rs:8:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    solution_test::test_full

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--test solution_test'
Деян Горанов
  • Коректно
  • 1 успешни тест(а)
  • 0 неуспешни тест(а)
Деян Горанов

pub fn fib(n: u32) -> u32 {
if n == 0 || n == 1 {
1
}
else {
fib(n-1) + fib(n-2)
}
}
Compiling solution v0.1.0 (/tmp/d20201014-2816268-2imelo/solution)
    Finished test [unoptimized + debuginfo] target(s) in 1.02s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 1 test
test solution_test::test_full ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out