# Фибоначи

Краен срок
11.10.2022 20:23
Точки
2

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

use solution::*;
#[test]
fn test_full() {
assert_eq!(fib(0), 0);
assert_eq!(fib(1), 1);
assert_eq!(fib(2), 0 + 1);
assert_eq!(fib(3), 1 + 1);
assert_eq!(fib(4), 1 + 2);
assert_eq!(fib(5), 2 + 3);
assert_eq!(fib(6), 3 + 5);
assert_eq!(fib(7), 5 + 8);
assert_eq!(fib(8), 8 + 13);
assert_eq!(fib(9), 13 + 21);
assert_eq!(fib(10), 21 + 34);
assert_eq!(fib(11), 34 + 55);
assert_eq!(fib(12), 55 + 89);
assert_eq!(fib(13), 89 + 144);
}

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

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

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

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


## Решения

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

pub fn fib(n: u32) -> u32 {
if n <= 1 {
n
} else {
fib(n - 1) + fib(n - 2)
}
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-ormdmn/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.59s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n == 0 {
return 0;
}
if n == 1 {
return 1;
}
fib(n - 1) + fib(n - 2)
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-gv62el/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.55s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
let mut curr = 0;
let mut next = 1;
let mut i = n;
while i > 0 {
let temp = curr + next;
curr = next;
next = temp;
i -= 1;
}
curr
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-1liu01o/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n == 0 || n == 1 {
return n;
}
let mut a = 0;
let mut b = 1;
for _i in 1..n {
let c = a + b;
a = b;
b = c;
}
b
}
fn main() {
let n = 6;
println!("Fib {}", fib(n));
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-6bhgnd/solution)
warning: function main is never used
--> src/lib.rs:15:4
|
15 | fn main() {
|    ^^^^
|
= note: #[warn(dead_code)] on by default

warning: solution (lib) generated 1 warning
Finished test [unoptimized + debuginfo] target(s) in 0.52s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n == 0 {
return 0;
}
if n == 1 {
return 1;
}
fib(n-1) + fib(n-2)
}
pub fn fib_iter(n: u32) -> u32 {
let mut a: u32 = 0;
let mut b: u32 = 1;
for _i in 0..n {
let tmp: u32 = b;
b += a;
a = tmp;
}
a
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-1rby7u7/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.58s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n==0 { return 0;}
if n==1 { return 1;}
let mut last: u32=0;
let mut curr: u32=1;
let mut num: u32=0;
for _i in 2..=n {
num = last + curr;
last = curr;
curr = num;
}
return num;
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-1wnbmvj/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.52s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n == 0
{
return 0;
} else if n==1 {
return 1;
} else
{
let mut pl1 = 0;
let mut pl2 = 1;
let mut next;
for _i in 2..(n+1)
{
next=pl1+pl2;
pl1 = pl2;
pl2 = next
}
return pl2;
}
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-1bon5ep/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.58s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n == 1{
return 0;
}
let mut temp1: u32 = 0;
let mut temp2: u32 = 1;
for _ in 1..n{
temp1 = temp1 + temp2;
temp2 = temp1 - temp2;
}
temp1
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-jf19wz/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.51s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

failures:

---- solution_test::test_full stdout ----
thread 'solution_test::test_full' panicked at 'assertion failed: (left == right)
left: 0,
right: 1', tests/solution_test.rs:7: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; finished in 0.00s

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

pub fn fib(n: u32) -> u32 {
if n == 0
{
return 0;
}
if n == 1
{
return 1;
}
let mut a: u32 = 0;
let mut b: u32 = 1;
let mut index: u32 = 2;
let mut res: u32 = 0;
while index <= n
{
res = a + b;
a = b;
b = res;
index+=1;
}
res
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-uaby12/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.51s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n == 0 {
return 0;
}
let mut last = 0;
let mut current = 1;
for _ in 1..n {
let temp = current;
current = current + last;
last = temp;
}
current
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-1n6vfe6/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.52s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n <= 1 {
n
} else {
fib(n - 1) + fib(n - 2)
}
// or alternatively
/*
match n {
0..=1 => n,
_ => fib(n - 1) + fib(n - 2)
}
*/
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-wyl5vq/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n == 0 {
return 0;
} else if n == 1 {
return 1;
} else {
return fib(n-1) + fib(n-2);
}
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-1qlxxzj/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
let fib = fibonachi(n, 0, 1);
return fib;
}
fn fibonachi(mut n: u32, n1: u32, n2: u32) -> u32 {
if n > 0 {
n-=1;
return fibonachi(n, n2, n1 + n2);
}
return n1;
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-1dlns4f/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.52s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
• Некоректно
• 0 успешни тест(а)
• 1 неуспешни тест(а)
Стоян Цветков

pub fn fib(n: u32) -> u32
{
let mut res=0_u32;
let mut prev=1_u32;
let mut old : u32;
if n==0
{
return 0;
}
else if n==1
{
return 1;
}
for _help in 1..n
{
old=prev;
prev=res;
res=prev+old;
}
res
}
fn main()
{
println!("0 {}\n1 {}\n2 {}\n4 {}\n8 {}",fib(0), fib(1), fib(2), fib(4), fib(8));
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-199u2ev/solution)
warning: function main is never used
--> src/lib.rs:23:4
|
23 | fn main()
|    ^^^^
|
= note: #[warn(dead_code)] on by default

warning: solution (lib) generated 1 warning
Finished test [unoptimized + debuginfo] target(s) in 0.59s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

failures:

---- solution_test::test_full stdout ----
thread 'solution_test::test_full' panicked at 'assertion failed: (left == right)
left: 1,
right: 2', tests/solution_test.rs:9: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; finished in 0.00s

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

pub fn fib(n: u32) -> u32 {
if (n==0) || (n==1){
n
} else {
fib(n-1) + fib(n-2)
}
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-1x1u5t6/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n==0 {
return 0;
}else if n==1 {
return 1;
}else {
return fib(n-2) +fib(n-1);
}
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-15fmu0e/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.58s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

fn main() {
let x = fib(5);
println!("{x}");
}
pub fn fib(n: u32) -> u32 {
if n == 0 {
return 0;
}
if n == 1 {
return 1;
}
fib(n - 1) + fib(n - 2)
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-gng964/solution)
warning: function main is never used
--> src/lib.rs:1:4
|
1 | fn main() {
|    ^^^^
|
= note: #[warn(dead_code)] on by default

warning: solution (lib) generated 1 warning
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n <= 1 {
n
} else {
fib(n - 1) + fib(n - 2)
}
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-xlz8vo/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
let res : u32;
if n == 0 {
res = 0;
} else if n == 1 {
res = 1;
} else {
res = fib(n-1) + fib(n-2)
}
res
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-13ntl7t/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n == 0 || n == 1 {
return n;
}
fib(n - 1) + fib(n - 2)
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-3jntrx/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n == 0 {
return 0;
}
if n == 1 {
return 1;
}
fib(n-1) + fib(n-2)
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-gg7nr4/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.51s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n == 0 {
return 0;
}
else if n == 1 {
return 1;
}
else {
return fib(n - 1) + fib(n - 2);
}
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-1kc30r/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.49s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
• Коректно
• 1 успешни тест(а)
• 0 неуспешни тест(а)
Берна Ахад

pub fn fib(n: u32) -> u32 {
if n == 0 {
return 0;
} else {
let mut l = 0;
let mut r = 1;
let mut iteration = 2;
while iteration <= n {
let sum = l + r;
l = r;
r = sum;
iteration+=1;
}
return r;
};
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-1j9cmme/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.51s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
• Коректно
• 1 успешни тест(а)
• 0 неуспешни тест(а)
Симеон Кънчев

pub fn fib(n: u32) -> u32 {
match n {
0 => 0,
1 => 1,
_ => fib(n - 1) + fib(n - 2)
}
}
fn main() {
for i in 0..10 {
println!("{}", fib(i));
}
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-107i2bk/solution)
warning: function main is never used
--> src/lib.rs:10:4
|
10 | fn main() {
|    ^^^^
|
= note: #[warn(dead_code)] on by default

warning: solution (lib) generated 1 warning
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
let (mut first, mut second) = (0, 1);
if n < 2 {
n
} else {
for _ in 2..=n {
(first, second) = (second, first + second);
}
second
}
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-bxnh1n/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.51s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

// reused my own solution of the same problem from the past edition of the course
pub fn fib(n: u32) -> u32 {
if n == 0 { return 0 }
if n == 1 { return 1 }
else { return fib(n - 1) + fib(n - 2) }
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-w56r2m/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
match n {
0 => 0,
1 => 1,
_ => fib(n - 1) + fib(n - 2)
}
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-1rrf9e5/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
let mut init1: u32 = 0;
let mut init2: u32 = 1;
let mut tmp: u32;
for _ in 0..n {
tmp = init2;
init2 += init1;
init1 = tmp;
}
return init1;
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-1upj5nc/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.51s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n==0 {
0
} else if n==1 {
1
} else {
fib(n - 1) + fib(n - 2)
}
}
//I found also a solve with "match" as I was looking through some materials
//Even though it's the same logic I think it represents the possibilities in the rust language better
//fn fib(n: u32) -> u32 {
// match n {
// 0 => 1,
// 1 => 1,
// _ => fib(n - 1) + fib(n - 2),
// }
//}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-mjzj1j/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n == 0 {
return 0;
} else if n == 1 {
return 1;
} else {
return fib(n - 1) + fib(n - 2);
}
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-11tn7af/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n <= 1 {
return n;
}
let mut first:u32 = 0;
let mut second:u32 = 1;
for _current in 1..n+1 {
if first == 0 {
first = second;
continue;
}
let temporary = first;
first = second;
second = first + temporary;
}
return first;
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-17kzjo2/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.52s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

// Doesn't seem like good practice to pass arrays like dis
fn optfib(a: u32, slice : &mut [u32;100]) -> u32 {
if slice[a as usize] != 0 {return slice[a as usize];}; // Not sure if I can go around [a as usize] as it is kinda annoying to type everytime
if a == 0 {return 0 as u32;};
if a == 1 {return 1 as u32;};
slice[a as usize] = (optfib(a - 1,slice) + optfib(a - 2,slice)) as u32; //If I can get feedback why I can't use this as a return statement like in C++ I'll be very glad
optfib(a - 1,slice) + optfib(a - 2,slice) // Cause if i could this line would be useless
}
pub fn fib(n: u32) -> u32 {
let mut array : [u32;100] = [0;100];
optfib(n, &mut array)
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-1ol7alx/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n == 0 || n == 1 {
return n;
}
let mut temp: u32;
let mut fib_prev: u32 = 0;
let mut fib_curr: u32 = 1;
for _fib_i in 1..n {
temp = fib_curr;
fib_curr = fib_prev + fib_curr;
fib_prev = temp;
}
fib_curr
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-in7wt5/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.52s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
match n {
0 => 0,
1 => 1,
_ => fib(n - 1) + fib(n - 2),
}
}
fn main() {
println!("{}", fib(10));
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-j36s8m/solution)
warning: function main is never used
--> src/lib.rs:10:4
|
10 | fn main() {
|    ^^^^
|
= note: #[warn(dead_code)] on by default

warning: solution (lib) generated 1 warning
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
• Коректно
• 1 успешни тест(а)
• 0 неуспешни тест(а)
Георги Низамски

pub fn fib(n: u32) -> u32 {
if n == 0 {
return 0
}
if n == 1 {
return 1
}
fib(n - 1) + fib(n - 2)
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-4vzow5/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n == 0 {
return 0;
} else if n == 1 {
return 1;
} else {
return fib(n - 1) + fib(n - 2);
}
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-d5uf3x/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n < 2
{
n
} else
{
fib(n-1) + fib(n-2)
}
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-1xqrkx3/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

use std::env;
pub fn fib(n: u32) -> u32 {
let (mut x1,mut x2,mut sum,mut iter) = (0u32, 1u32, 0u32, 2u32);
if n < 2 {
n
} else {
while iter <= n
{
sum = x1 + x2;
x1 = x2;
x2 = sum;
iter += 1
}
sum
}
}
fn main() {
let args:Vec<_> = env::args().collect();
let param;
if args.len() > 1 {
param = args.parse::<u32>().unwrap();
println!("Nth Fibonacci number is: {}", fib(param))
}
else {
println!("At least one argument is needed.");
}
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-u6cxcl/solution)
warning: function main is never used
--> src/lib.rs:21:4
|
21 | fn main() {
|    ^^^^
|
= note: #[warn(dead_code)] on by default

warning: solution (lib) generated 1 warning
Finished test [unoptimized + debuginfo] target(s) in 0.61s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n == 0 { return n; }
if n == 1 { return n; }
return fib(n-1) + fib(n-2);
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-13xhqk/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n==0 || n==1 {
return n
}
fib(n-1) + fib(n-2)
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-bdyltg/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.50s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

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

pub fn fib(n: u32) -> u32 {
if n==0 {
return 0
}
else if n==1 {
return 1
}
else {
fib(n-1) + fib(n-2)
}
}
Compiling solution v0.1.0 (/tmp/d20221011-1221210-quk1yy/solution)
Finished test [unoptimized + debuginfo] target(s) in 0.55s
Running tests/solution_test.rs (target/debug/deps/solution_test-867d7317a91c4f07)

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

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s