Skip to content

Commit d51b14b

Browse files
committed
Add problem 3274: Check if Two Chessboard Squares Have the Same Color
1 parent 92e49f2 commit d51b14b

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,6 +2164,7 @@ pub mod problem_3259_maximum_energy_boost_from_two_drinks;
21642164
pub mod problem_3264_final_array_state_after_k_multiplication_operations_i;
21652165
pub mod problem_3270_find_the_key_of_the_numbers;
21662166
pub mod problem_3271_hash_divided_string;
2167+
pub mod problem_3274_check_if_two_chessboard_squares_have_the_same_color;
21672168
pub mod problem_3350_adjacent_increasing_subarrays_detection_ii;
21682169

21692170
#[cfg(test)]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
pub struct Solution;
2+
3+
// ------------------------------------------------------ snip ------------------------------------------------------ //
4+
5+
impl Solution {
6+
pub fn check_two_chessboards(coordinate1: String, coordinate2: String) -> bool {
7+
((coordinate1.bytes().sum::<u8>() ^ coordinate2.bytes().sum::<u8>()) & 1) == 0
8+
}
9+
}
10+
11+
// ------------------------------------------------------ snip ------------------------------------------------------ //
12+
13+
impl super::Solution for Solution {
14+
fn check_two_chessboards(coordinate1: String, coordinate2: String) -> bool {
15+
Self::check_two_chessboards(coordinate1, coordinate2)
16+
}
17+
}
18+
19+
#[cfg(test)]
20+
mod tests {
21+
#[test]
22+
fn test_solution() {
23+
super::super::tests::run::<super::Solution>();
24+
}
25+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
pub mod iterative;
2+
3+
pub trait Solution {
4+
fn check_two_chessboards(coordinate1: String, coordinate2: String) -> bool;
5+
}
6+
7+
#[cfg(test)]
8+
mod tests {
9+
use super::Solution;
10+
11+
pub fn run<S: Solution>() {
12+
let test_cases = [(("a1", "c3"), true), (("a1", "h3"), false)];
13+
14+
for ((coordinate1, coordinate2), expected) in test_cases {
15+
assert_eq!(
16+
S::check_two_chessboards(coordinate1.to_string(), coordinate2.to_string()),
17+
expected,
18+
);
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)