palindronum

Crates.iopalindronum
lib.rspalindronum
version1.0.2
sourcesrc
created_at2023-07-05 14:02:40.39871
updated_at2024-04-23 12:58:25.480608
descriptionNumber palindromes
homepage
repositoryhttps://github.com/EngosSoftware/palindronum.git
max_upload_size
id909087
size29,004
core (github:engossoftware:core)

documentation

https://docs.rs/palindronum

README

Crates.io MIT licensed Apache 2.0 licensed Contributor Covenant

Number palindromes

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

License

Licensed under either of

at your option.

Contribution

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.

Commit count: 3

cargo fmt