[rs] Use some fancy rust features

This commit is contained in:
Joscha 2022-12-16 00:21:17 +01:00
parent a396c81172
commit cc8fe30a36
2 changed files with 4 additions and 5 deletions

View file

@ -81,9 +81,8 @@ fn draw_floor(grid: &mut Grid) {
/// ///
/// This function will return `true` if it managed to deposit a unit of sand. /// This function will return `true` if it managed to deposit a unit of sand.
fn drop(grid: &mut Grid, path: &mut Vec<(i32, i32)>, max_y: i32) -> bool { fn drop(grid: &mut Grid, path: &mut Vec<(i32, i32)>, max_y: i32) -> bool {
let (mut x, mut y) = match path.last() { let Some((mut x, mut y)) = path.last() else {
Some(pos) => pos, return false;
None => return false,
}; };
loop { loop {

View file

@ -126,7 +126,7 @@ pub fn solve(input: String) {
lines_trbl.push((p.0 + d + 1, p.1, p.0, p.1 + d + 1)); lines_trbl.push((p.0 + d + 1, p.1, p.0, p.1 + d + 1));
} }
for tlbr in &lines_tlbr { 'outer: for tlbr in &lines_tlbr {
for trbl in &lines_trbl { for trbl in &lines_trbl {
if let Some(intersect) = intersect_lines(*tlbr, *trbl) { if let Some(intersect) = intersect_lines(*tlbr, *trbl) {
let x_in_bounds = 0 <= intersect.0 && intersect.0 <= 4000000; let x_in_bounds = 0 <= intersect.0 && intersect.0 <= 4000000;
@ -147,7 +147,7 @@ pub fn solve(input: String) {
// We found our candidate :) // We found our candidate :)
let tuning_frequency = intersect.0 as i64 * 4000000 + intersect.1 as i64; let tuning_frequency = intersect.0 as i64 * 4000000 + intersect.1 as i64;
println!("Part 2: {tuning_frequency}"); println!("Part 2: {tuning_frequency}");
return; break 'outer;
} }
} }
} }