Advertisement
Guest User

fuck

a guest
Dec 3rd, 2018
35
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #![feature(box_syntax)] // fuck you
  2. extern crate regex;
  3. use regex::Regex;
  4.  
  5. struct Claim {
  6.     id: i32,
  7.     x: i32,
  8.     y: i32,
  9.     w: i32,
  10.     h: i32,
  11. }
  12.  
  13. fn main() -> Result<(), Box<std::error::Error>> {
  14.     let mut areas = box [[0; 1001]; 1001];
  15.     let mut claims = Vec::<Claim>::new();
  16.     let input = include_str!("../input.txt");
  17.  
  18.     let pattern = Regex::new(r"#(\d+) @ (\d+),(\d+): (\d+)x(\d+)").unwrap();
  19.     for caps in pattern.captures_iter(input) {
  20.         let claim = Claim {
  21.             id: caps.get(1).unwrap().as_str().parse::<i32>()?,
  22.             x: caps.get(2).unwrap().as_str().parse::<i32>()?,
  23.             y: caps.get(3).unwrap().as_str().parse::<i32>()?,
  24.             w: caps.get(4).unwrap().as_str().parse::<i32>()?,
  25.             h: caps.get(5).unwrap().as_str().parse::<i32>()?,
  26.         };
  27.  
  28.         for i in claim.x..claim.x+claim.w {
  29.             for j in claim.y..claim.y+claim.h {
  30.                 areas[i as usize][j as usize] += 1;
  31.             }
  32.         }
  33.  
  34.         claims.push(claim);
  35.     }
  36.  
  37.     let mut twos = 0;
  38.  
  39.     for i in 0..1001 {
  40.         for j in 0..1001 {
  41.             if areas[i][j] >= 2 {
  42.                 twos += 1;
  43.             }
  44.         }
  45.     }
  46.  
  47.     for claim in claims.iter() {
  48.         let mut has_overlap = false;
  49.         for i in claim.x..claim.x+claim.w {
  50.             for j in claim.y..claim.y+claim.h {
  51.                 if areas[i as usize][j as usize] != 1 {
  52.                     has_overlap = true;
  53.                 }
  54.             }
  55.         }
  56.  
  57.         if !has_overlap {
  58.             println!("pure no overlap boy: {}", claim.id);
  59.         }
  60.     }
  61.  
  62.     println!("there are fucking {} overlapped square inch things in this", twos);
  63.    
  64.     Ok(())
  65. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement