Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: enforce nonegative inputs by using u32 in lucas_series #640

Merged
merged 3 commits into from
Dec 31, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
refactor: enforce nonegative inputs by using u32
  • Loading branch information
vil02 committed Dec 30, 2023
commit 0b4fe2b484421a8b8618bb80559553108fc49422
10 changes: 2 additions & 8 deletions src/math/lucas_series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@
// Wikipedia Reference : https://en.wikipedia.org/wiki/Lucas_number
// Other References : https://the-algorithms.com/algorithm/lucas-series?lang=python

pub fn recursive_lucas_number(n: i32) -> i32 {
if n < 0 {
panic!("sorry, this function accepts only non-negative integer arguments.");
}
pub fn recursive_lucas_number(n: u32) -> u32 {
match n {
0 => 2,
1 => 1,
_ => recursive_lucas_number(n - 1) + recursive_lucas_number(n - 2),
}
}

pub fn dynamic_lucas_number(n: i32) -> i32 {
if n < 0 {
panic!("sorry, this functionc accepts only non-negative integer arguments.");
}
pub fn dynamic_lucas_number(n: u32) -> u32 {
let mut a = 2;
let mut b = 1;

Expand Down