RosettaCodeData/Task/Palindrome-detection/Rust/palindrome-detection-1.rust

26 lines
558 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
fn is_palindrome(string: &str) -> bool {
let half_len = string.len() / 2;
string
.chars()
.take(half_len)
.eq(string.chars().rev().take(half_len))
}
macro_rules! test {
( $( $x:tt ),* ) => { $( println!("'{}': {}", $x, is_palindrome($x)); )* };
}
fn main() {
test!(
"",
"a",
"ada",
"adad",
"ingirumimusnocteetconsumimurigni",
"人人為我,我為人人",
"Я иду с мечем, судия",
"아들딸들아",
"The quick brown fox"
);
}