diff --git a/rust/.gitignore b/rust/.gitignore new file mode 100644 index 0000000..9f97022 --- /dev/null +++ b/rust/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/rust/Cargo.lock b/rust/Cargo.lock new file mode 100644 index 0000000..b21cc6a --- /dev/null +++ b/rust/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "rust" +version = "0.1.0" diff --git a/rust/Cargo.toml b/rust/Cargo.toml new file mode 100644 index 0000000..84a8d29 --- /dev/null +++ b/rust/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "rust" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] \ No newline at end of file diff --git a/rust/tests/1_persistent_bugger.rs b/rust/tests/1_persistent_bugger.rs new file mode 100644 index 0000000..eac04c8 --- /dev/null +++ b/rust/tests/1_persistent_bugger.rs @@ -0,0 +1,24 @@ +fn persistence(num: u64) -> u64 { + match num { + 0..=9 => 0, + _ => { + let res = num + .to_string() + .chars() + .map(|c| c.to_digit(10).unwrap() as u64) + .product(); + 1 + persistence(res) + } + } +} + +#[cfg(test)] +mod tests { + #[test] + fn sample_tests() { + assert_eq!(super::persistence(39), 3); + assert_eq!(super::persistence(4), 0); + assert_eq!(super::persistence(25), 2); + assert_eq!(super::persistence(999), 4); + } +}