diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2023-04-12 04:58:02 +0200 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2023-04-12 04:58:02 +0200 |
| commit | 01fe0c7d69cfc15c44bf8da9e7bc12c4b4ced264 (patch) | |
| tree | e40648725f24912be8bac01385eb47219b39dce2 /2022/Rust/src/day10.rs | |
| parent | 1e8e58033cefcaf138c72085b1a5bffb8cd958c9 (diff) | |
| download | aoc-01fe0c7d69cfc15c44bf8da9e7bc12c4b4ced264.tar.xz aoc-01fe0c7d69cfc15c44bf8da9e7bc12c4b4ced264.zip | |
Day11 done in rust
Diffstat (limited to '2022/Rust/src/day10.rs')
| -rw-r--r-- | 2022/Rust/src/day10.rs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/2022/Rust/src/day10.rs b/2022/Rust/src/day10.rs index 992c503..92a27d4 100644 --- a/2022/Rust/src/day10.rs +++ b/2022/Rust/src/day10.rs @@ -27,13 +27,12 @@ impl Crt { } } - fn get_overlap_with_sprite(&self, sprite: &Sprite, cycle: i32) -> Option<i32> { + fn is_overlapping_with_sprite(&self, sprite: &Sprite, cycle: i32) -> Option<i32> { let x = cycle % 40; - if x == sprite.location || x == sprite.location - 1 || x == sprite.location + 1 { - Some(x) - } else { - None + if ((x - 1)..=(x + 1)).contains(&sprite.location) { + return Some(x); } + None } } @@ -129,7 +128,7 @@ fn solve_part_two(data: &str) { y_val += 1; } } - match crt.get_overlap_with_sprite(&sprite, cur_cycle) { + match crt.is_overlapping_with_sprite(&sprite, cur_cycle) { Some(idx) => crt.pixels[y_val as usize] .replace_range((idx as usize)..=idx as usize, "#"), None => {} @@ -144,7 +143,7 @@ fn solve_part_two(data: &str) { y_val += 1; } } - match crt.get_overlap_with_sprite(&sprite, cur_cycle) { + match crt.is_overlapping_with_sprite(&sprite, cur_cycle) { Some(idx) => { crt.pixels[y_val as usize].replace_range((idx as usize)..=idx as usize, "#") } |
