20241209 finished.
This commit is contained in:
parent
bc89dfbffe
commit
53a8fda797
|
@ -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;
|
||||
|
|
41
src/problem/p1812_determine_color_of_a_chessboard_square.rs
Normal file
41
src/problem/p1812_determine_color_of_a_chessboard_square.rs
Normal 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()));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user