close
Skip to main content
nebkor u/nebkor avatar

nebkor

u/nebkor

Feed options
Hot
New
Top
View
Card
Compact

Awesome!


So, I'm actually finding a lot of typos in my early edition :) I've been marking them; is there a place for submitting or searching for errata?


I found it easier to allocate an output buffer, then send mutable chunks into a multiconsumer queue, where rendering worker threads can grab them and fill them in with pixel data. Most of the time is spent calculating random numbers, so I wanted a pool of threads that each had their own RNG.

https://gitlab.com/nebkor/weekend-raytracer/-/commit/c95b071e835d9a35fc523b0863d103fa6ad7503c


It's too bad cops are cowardly trigger-happy babies.


It's not the individuals; it's the entire system and culture.

How many bad apples before the bunch is spoiled?


Oh, I like the way you just 'include_str!' the data; I have a tiny private crate that uses clap to parse the input for a filename. Part 2 is solved by adding to part 1's solution a set of IDs that is initialized to contain all the claim IDs ("singles"), then while going over all the coordinates, removing the IDs of any contained in a square with more than one claim. Running time is O(n) for number of claims, space requirement is O(max_claim_x * max_claim_y).

use lazy_static::*;
use regex::Regex;
use std::collections::{HashMap, HashSet};
use utils::*;

struct Claim {
    pub id: u32,
    xrange: (u32, u32),
    yrange: (u32, u32),
}

impl Claim {
    fn new(ent: &str) -> Self {
        lazy_static! {
            static ref RE: Regex = Regex::new(r"#(\d+) @ (\d+,\d+): (\d+x\d+)").unwrap();
        }

        let caps = RE.captures(ent).unwrap();
        let id: u32 = caps[1].parse().unwrap();
        let startx: u32 = caps[2].split(',').collect::<Vec<_>>()[0].parse().unwrap();
        let starty: u32 = caps[2].split(',').collect::<Vec<_>>()[1].parse().unwrap();
        let spanx: u32 = caps[3].split('x').collect::<Vec<_>>()[0].parse().unwrap();
        let spany: u32 = caps[3].split('x').collect::<Vec<_>>()[1].parse().unwrap();

        Claim {
            id,
            xrange: (startx, startx + spanx),
            yrange: (starty, starty + spany),
        }
    }

    fn startx(&self) -> u32 {
        self.xrange.0
    }
    fn endx(&self) -> u32 {
        self.xrange.1
    }

    fn starty(&self) -> u32 {
        self.yrange.0
    }
    fn endy(&self) -> u32 {
        self.yrange.1
    }
}
    
fn main() {
    let input = get_input("day3");

    let file = read_file(&input);

    let mut cloth_map: HashMap<(u32, u32), HashSet<u32>> = HashMap::new(); // coordinates to IDs
    let mut singles: HashSet<u32> = HashSet::new();

    for entry in file.lines() {
        let claim = Claim::new(&entry.unwrap());
        let _ = singles.insert(claim.id);

        for x in claim.startx()..claim.endx() {
            for y in claim.starty()..claim.endy() {
                cloth_map
                    .entry((x, y))
                    .or_insert(HashSet::new())
                    .insert(claim.id);
            }
        }
    }

    let tot: u32 = cloth_map
        .values()
        .map(|s| match s.len() {
            x if x > 1 => {
                for id in s.iter() {
                    let _ = singles.remove(id);
                }
                1
            }
            _ => 0,
        })
        .sum();
    println!("Found {} square inches multiply-claimed.", tot);

    for id in singles.iter() {
        println!("Only {} made it through intact.", id);
    }
}

Feel free to stay home, but protests are an important mechanism for energizing change. Making it hurt for people who refuse to be part of the solution is important.

Telling people to stay home and not organize is bootlicking horseshit, and supports the status quo. It's incredibly bad practice, and you should understand that.


Collusion is not a crime, so, who cares.

What's extremely likely is that Trump's entire life is basically an exploration of the space of possible crimes related to finance and betrayal, as is the lives of all those around him. Once a competent eye is turned on those lives, rich veins of indictable felonies come to the surface, and this fact is starting to sink in for them.