Crates.io | palindronum |
lib.rs | palindronum |
version | 1.0.2 |
source | src |
created_at | 2023-07-05 14:02:40.39871 |
updated_at | 2024-04-23 12:58:25.480608 |
description | Number palindromes |
homepage | |
repository | https://github.com/EngosSoftware/palindronum.git |
max_upload_size | |
id | 909087 |
size | 29,004 |
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). 0 is treated as a palindrome.
To check if a number is a palindrome, use is_palindrome function, e.g.:
let x = 123; // no, this is not a palindrome
let is_palindrome = palindronum::is_palindrome(x);
println!("{x} is a palindrome: {is_palindrome}");
output:
123 is a palindrome: false
let x = 121; // yes, this is a palindrome
let is_palindrome = palindronum::is_palindrome(x);
println!("{x} is a palindrome: {is_palindrome}");
output:
121 is a palindrome: true
To generate first n palindromes, use first_n_palindromes function, e.g.:
let first_10_palindromes = palindronum::first_n_palindromes(10);
for x in first_10_palindromes {
println!("{x:2} is a palindrome");
}
output:
1 is a palindrome
2 is a palindrome
3 is a palindrome
4 is a palindrome
5 is a palindrome
6 is a palindrome
7 is a palindrome
8 is a palindrome
9 is a palindrome
11 is a palindrome
Licensed under either of
at your option.
Any contributions to palindronum are greatly appreciated. All contributions intentionally submitted for inclusion in the work by you, shall be dual licensed as above, without any additional terms or conditions.