Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(box_syntax)] // fuck you
- extern crate regex;
- use regex::Regex;
- struct Claim {
- id: i32,
- x: i32,
- y: i32,
- w: i32,
- h: i32,
- }
- fn main() -> Result<(), Box<std::error::Error>> {
- let mut areas = box [[0; 1001]; 1001];
- let mut claims = Vec::<Claim>::new();
- let input = include_str!("../input.txt");
- let pattern = Regex::new(r"#(\d+) @ (\d+),(\d+): (\d+)x(\d+)").unwrap();
- for caps in pattern.captures_iter(input) {
- let claim = Claim {
- id: caps.get(1).unwrap().as_str().parse::<i32>()?,
- x: caps.get(2).unwrap().as_str().parse::<i32>()?,
- y: caps.get(3).unwrap().as_str().parse::<i32>()?,
- w: caps.get(4).unwrap().as_str().parse::<i32>()?,
- h: caps.get(5).unwrap().as_str().parse::<i32>()?,
- };
- for i in claim.x..claim.x+claim.w {
- for j in claim.y..claim.y+claim.h {
- areas[i as usize][j as usize] += 1;
- }
- }
- claims.push(claim);
- }
- let mut twos = 0;
- for i in 0..1001 {
- for j in 0..1001 {
- if areas[i][j] >= 2 {
- twos += 1;
- }
- }
- }
- for claim in claims.iter() {
- let mut has_overlap = false;
- for i in claim.x..claim.x+claim.w {
- for j in claim.y..claim.y+claim.h {
- if areas[i as usize][j as usize] != 1 {
- has_overlap = true;
- }
- }
- }
- if !has_overlap {
- println!("pure no overlap boy: {}", claim.id);
- }
- }
- println!("there are fucking {} overlapped square inch things in this", twos);
- Ok(())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement