20241209 finished.

This commit is contained in:
jackfiled 2024-12-09 11:43:05 +08:00
parent bc89dfbffe
commit 53a8fda797
2 changed files with 43 additions and 0 deletions

View File

@ -358,3 +358,5 @@ mod p999_available_captures_for_rook;
mod p688_knight_probability_in_chessboard;
mod p782_transform_to_chessboard;
mod p1812_determine_color_of_a_chessboard_square;

View File

@ -0,0 +1,41 @@
/**
* [1812] Determine Color of a Chessboard Square
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn square_is_white(coordinates: String) -> bool {
let mut coordinates = coordinates.chars();
let (x, y) = (coordinates.next().unwrap(), coordinates.next().unwrap());
match x {
'a' | 'c' | 'e' | 'g' => match y {
'1' | '3' | '5' | '7' => false,
'2' | '4' | '6' | '8' => true,
_ => unimplemented!(),
},
'b' | 'd' | 'f' | 'h' => match y {
'1' | '3' | '5' | '7' => true,
'2' | '4' | '6' | '8' => false,
_ => unimplemented!(),
},
_ => unimplemented!(),
}
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_1812() {
assert!(!Solution::square_is_white("a1".to_owned()));
assert!(Solution::square_is_white("h3".to_owned()));
assert!(!Solution::square_is_white("c7".to_owned()));
}
}