6 releases
0.1.5 | Oct 15, 2023 |
---|---|
0.1.4 | Oct 15, 2023 |
#750 in Math
9KB
68 lines
Palindrome number library prototype
Definitions
A "palindrome" is a number that is the same when the digits are reversed. For example, 121, 2332, and 6 are all palindromes. But 10 is not a palindrome (since leading zeroes are not allowed). Treat 0 as a palindrome, and use an unsigned integer type.
Goal
Write crate that allows the user to:
- check if a number is a palindrome
- generate the first N palindromes
Assumptions
- No need to deal with numbers greater than 1,000,000.
- Code may panic if it is called with any values that would result in a number greater than 1,000,000 being generated.
- 3rd-party crates can be used, but they may not appear in your public API.
Constrains
If a crate literally implements the question as-is, don't use it.
Crate location
- The code itself can be found on github.com.
- It is uploaded on crates.io and can be used directly as dependency in Cargo.toml:
...
[dependencies]
bs_crate = "0.1.0"
...
Using
The crate should be used like this:
use bs_crate;
fn main() {
let x = 123;
let is_palindrome = bs_crate::is_palindrome(x);
println!("{x} is a palindrome: {is_palindrome}");
let first_10_palindromes = bs_crate::first_n_palindromes(10);
for x in first_10_palindromes {
println!("{x} is a palindrome");
}
}