Day 15, puzzle 2
This commit is contained in:
		
							
								
								
									
										33
									
								
								src/bin/d15p2.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/bin/d15p2.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,33 @@
 | 
			
		||||
use aoc22::{day15, util};
 | 
			
		||||
use itertools::Itertools;
 | 
			
		||||
 | 
			
		||||
const COORD_MAX: isize = 4000000;
 | 
			
		||||
 | 
			
		||||
pub fn main() {
 | 
			
		||||
    let sensors = day15::parse_sensors(&util::parse_input());
 | 
			
		||||
 | 
			
		||||
    for row in 0..=COORD_MAX {
 | 
			
		||||
        let covered = sensors
 | 
			
		||||
            .iter()
 | 
			
		||||
            .map(|s| s.covered(row))
 | 
			
		||||
            .filter(|r| !r.is_empty())
 | 
			
		||||
            .sorted_by_key(|r| *r.start());
 | 
			
		||||
 | 
			
		||||
        let mut max_x = isize::MIN;
 | 
			
		||||
        for range in covered {
 | 
			
		||||
            let (min, max) = range.into_inner();
 | 
			
		||||
            if min == max_x + 2 {
 | 
			
		||||
                let x = max_x + 1;
 | 
			
		||||
                println!(
 | 
			
		||||
                    "x = {}, y = {}, tuning freq = {}",
 | 
			
		||||
                    x,
 | 
			
		||||
                    row,
 | 
			
		||||
                    x * 4000000 + row
 | 
			
		||||
                )
 | 
			
		||||
            } else if max_x != isize::MIN && min > max_x + 2 {
 | 
			
		||||
                panic!("More than one coordinate free: {}..{}", max_x + 1, min - 1);
 | 
			
		||||
            }
 | 
			
		||||
            max_x = max_x.max(max);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user