1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-16 20:56:57 +02:00
CodeWars/5kyu/perimeter_of_squares_in_a_rectangle/solution.rs
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

21 lines
419 B
Rust

use std::vec::Vec;
fn fibonacci(n: u64) -> Vec<u64> {
match n {
0 => vec![1],
1 => vec![1, 1],
_ => {
let mut result = vec![1, 1];
for i in 2..(n as usize + 1) {
result.push(result[i - 1] + result[i - 2]);
}
result
}
}
}
pub fn perimeter(n: u64) -> u64 {
fibonacci(n).iter().fold(0, |acc, x| acc + 4 * x)
}