Skip to content

EngosSoftware/palindronum

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.

About

Number palindromes

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE
MIT
LICENSE-MIT

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages