DeaconBlue's recent activity

  1. Comment on Lord Of The Rings author's writing desk up for auction in ~books

    DeaconBlue
    Link Parent
    Honestly this just made me confused, like maybe it was some kind of co-author situation that they were trying to hype up.

    Honestly this just made me confused, like maybe it was some kind of co-author situation that they were trying to hype up.

    5 votes
  2. Comment on Day 5: Cafeteria in ~comp.advent_of_code

    DeaconBlue
    Link
    Running in 337.65µs on my machine, first sub-1ms entry so far this year! Order the ranges by the lower number. If the higher number in the range is larger than the next low number, merge the...

    Running in 337.65µs on my machine, first sub-1ms entry so far this year!

    Order the ranges by the lower number. If the higher number in the range is larger than the next low number, merge the ranges.

    Part 2
    use std::{
        env,
        fs::File,
        io::{self, BufRead},
        path::Path,
        time::Instant,
    };
    
    fn main() {
        let now = Instant::now();
        let args: Vec<String> = env::args().collect();
    
        let mut ranges = vec![];
        if let Ok(lines) = read_lines(&args[1]) {
            for line in lines {
                let line = line.expect("");
                if line.contains("-") {
                    let mut split = line.split("-");
                    ranges.push((
                        split.next().unwrap().parse::<i64>().unwrap(),
                        split.next().unwrap().parse::<i64>().unwrap(),
                    ));
                }
            }
        }
        ranges.sort();
    
        let mut i = 0;
        while i < ranges.len() - 1 {
            if !(ranges[i].1 < ranges[i + 1].0) {
                ranges[i + 1] = (
                    (ranges[i].0).min(ranges[i + 1].0),
                    (ranges[i].1).max(ranges[i + 1].1),
                );
                ranges.remove(i);
                continue;
            }
            i += 1;
        }
    
        let sum: i64 = ranges.into_iter().map(|x| x.1 - x.0 + 1).sum();
        println!("{sum}");
    
        let elapsed = now.elapsed();
        println!("Elapsed: {:.2?}", elapsed);
    }
    fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
    where
        P: AsRef<Path>,
    {
        let file = File::open(filename)?;
        Ok(io::BufReader::new(file).lines())
    }
    
    1 vote
  3. Comment on Day 4: Printing Department in ~comp.advent_of_code

    DeaconBlue
    (edited )
    Link
    @zkxs I stole your code for populating the grid from a file just because it was cleaner than mine and not particularly relevant for the actual challenge. I don't like defining the 139 size, I...

    @zkxs I stole your code for populating the grid from a file just because it was cleaner than mine and not particularly relevant for the actual challenge. I don't like defining the 139 size, I would rather read line length from the file from the argument, but it needed to be defined for the recursive function signature. Is this where macros come in?

    I learned a long time ago that when dealing with neighboring cells on a grid, it's often easier to just extend the grid by one in every direction and fill it with junk to make all of the neighbor checks cleaner.

    I solved this one earlier using the loop method where you keep checking the entire grid for any available to remove and removing them, but I wanted to take a swing at a recursive option. Iterate over the grid once, but whenever you remove a roll, see if it makes any new rolls available to be removed.

    This runs in 5ms on my machine which isn't really faster or slower than the original approach, but recursion always tickles my brain in a good way so I prefer this way.

    Part 2
    use std::{
        env,
        fs::File,
        io::{BufReader, Read},
        time::Instant,
    };
    
    const SQUARE_SIZE: usize = 139;
    const BIGGER_SQUARE: usize = SQUARE_SIZE + 2;
    
    fn main() {
        let now = Instant::now();
        let mut sum: i32 = 0;
        let args: Vec<String> = env::args().collect();
    
        let reader = BufReader::new(File::open(&args[1]).expect("Failure to open file"));
        let mut grid = [[0u8; BIGGER_SQUARE]; BIGGER_SQUARE];
        grid[1..BIGGER_SQUARE]
            .iter_mut()
            .flat_map(|x| x[1..BIGGER_SQUARE].iter_mut())
            .zip(reader.bytes())
            .for_each(|(dst, src)| {
                *dst = src.unwrap();
            });
    
        for x in 1..BIGGER_SQUARE - 1 {
            for y in 1..BIGGER_SQUARE - 1 {
                sum += check_neighbors(&mut grid, x, y)
            }
        }
        println!("Sum {sum}");
        let elapsed = now.elapsed();
        println!("Elapsed: {:.2?}", elapsed);
    }
    
    fn check_neighbors(grid: &mut [[u8; BIGGER_SQUARE]; BIGGER_SQUARE], x: usize, y: usize) -> i32 {
        let mut total = 0;
        let mut ret_val = 0;
        let mut cache = vec![];
        if grid[x][y] == b'@' {
            for i in 0..=2 {
                for j in 0..=2 {
                    if (i != 1 || j != 1) && grid[x + i - 1][y + j - 1] == b'@' {
                        cache.push((x + i - 1, y + j - 1));
                        total += 1;
                    }
                }
            }
            if total <= 3 {
                grid[x][y] = b'x';
                for cache_coord in cache {
                    ret_val += check_neighbors(grid, cache_coord.0, cache_coord.1);
                }
                ret_val += 1;
            }
        }
        return ret_val;
    }
    
    1 vote
  4. Comment on Bill Gates warns child deaths to rebound after Donald Trump-era funding cuts in ~society

    DeaconBlue
    Link Parent
    What an awful website. Why are people obsessed with hijacking scroll behavior like this?

    The report is here. Unfortunately it’s the online equivalent of a glossy brochure, which makes it harder to read.

    What an awful website. Why are people obsessed with hijacking scroll behavior like this?

    1 vote
  5. Comment on Day 3: Lobby in ~comp.advent_of_code

    DeaconBlue
    Link Parent
    I see. I am going to need to play with the language a bit more to make that intuitive!

    I see.

    I am going to need to play with the language a bit more to make that intuitive!

    2 votes
  6. Comment on Day 3: Lobby in ~comp.advent_of_code

    DeaconBlue
    Link Parent
    I think my confusion comes down to the borrow checker. I don't fully understand why I had to(?) make a copy of line into temp_line when I wasn't manipulating the line, just taking length and slices.

    I think my confusion comes down to the borrow checker. I don't fully understand why I had to(?) make a copy of line into temp_line when I wasn't manipulating the line, just taking length and slices.

    1 vote
  7. Comment on Day 3: Lobby in ~comp.advent_of_code

    DeaconBlue
    Link
    Well, I thought my solution was pretty acceptable until I read some others here. My strategy was to iterate 12 times across the string slices that were after the last chosen digit and before the...

    Well, I thought my solution was pretty acceptable until I read some others here. My strategy was to iterate 12 times across the string slices that were after the last chosen digit and before the required remainder.

    I also feel like I am using strings incorrectly here, but the compiler wanted nothing to do with me tonight.

    Part 2
    use std::{
        env,
        fs::File,
        io::{self, BufRead},
        path::Path,
        time::Instant,
    };
    
    fn main() {
        let now = Instant::now();
        let mut sum: i64 = 0;
    
        let args: Vec<String> = env::args().collect();
    
        if let Ok(lines) = read_lines(&args[1]) {
            for line in lines {
                let temp_line = line.expect("");
                let mut chars = vec![];
                let mut used_index = 0;
                let mut index = 12;
                while index > 0 {
                    let last_index = temp_line.len() - index;
                    let result = get_highest_char(&temp_line[used_index..last_index]);
                    chars.push(result.1);
                    used_index += result.0;
                    index -= 1;
                }
                println!("{:?}", chars);
                sum = sum
                    + chars
                        .into_iter()
                        .collect::<String>()
                        .parse::<i64>()
                        .expect("");
            }
            println!("{sum}");
        }
        let elapsed = now.elapsed();
        println!("Elapsed: {:.2?}", elapsed);
    }
    
    fn get_highest_char(available: &str) -> (usize, char) {
        let mut best_index = 0;
        let mut best_char = '0';
        let mut index = 0;
        for n in available.chars() {
            if n > best_char {
                best_char = n;
                best_index = index;
            }
            index += 1;
            if best_char == '9' {
                break;
            }
        }
        return (best_index, best_char);
    }
    
    fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
    where
        P: AsRef<Path>,
    {
        let file = File::open(filename)?;
        Ok(io::BufReader::new(file).lines())
    }
    
    1 vote
  8. Comment on Day 3: Lobby in ~comp.advent_of_code

    DeaconBlue
    Link Parent
    The steam deck is a perfectly cromulent little laptop, I use Blender on the thing for making game mods. Admittedly, you kind of do need a keyboard.

    The steam deck is a perfectly cromulent little laptop, I use Blender on the thing for making game mods. Admittedly, you kind of do need a keyboard.

    2 votes
  9. Comment on Advent of Code starts tomorrow/tonight! Are you participating? Do you have any specific plans for this year? in ~comp.advent_of_code

    DeaconBlue
    Link
    I am doing it in Rust this year to try to act like I have some idea of what I am doing with that language. I intend to check out others' answers after solving it to see if there are language...

    I am doing it in Rust this year to try to act like I have some idea of what I am doing with that language. I intend to check out others' answers after solving it to see if there are language features that I am using improperly or maybe don't know about. Excited for this year!

    2 votes
  10. Comment on Day 1: Secret Entrance in ~comp.advent_of_code

    DeaconBlue
    Link
    @creamsnail I'm not terribly happy with my algorithm for this one but it is just a warmup. The "stopping and starting on 0" bit threw me more than it should have. This solution contains both...

    @creamsnail

    I'm not terribly happy with my algorithm for this one but it is just a warmup. The "stopping and starting on 0" bit threw me more than it should have. This solution contains both answers, runs in ~50ms.

    Both parts
    use std::{
        env,
        fs::File,
        i32,
        io::{self, BufRead},
        path::Path,
        time::Instant,
    };
    
    fn main() {
        let now = Instant::now();
        let args: Vec<String> = env::args().collect();
        let mut current_val = 50;
        let mut zero_stops = 0;
        let mut zero_passes = 0;
        let upper_limit = 100;
        let lower_limit = 0;
        if let Ok(lines) = read_lines(&args[1]) {
            println!("The dial starts by pointing at {current_val}.");
            for line in lines.map_while(Result::ok) {
                let original_val = current_val.clone();
                let mut temp_passes = 0;
                let mut temp_stops = 0;
                let (direction, magnitude) = line.split_at(1);
                let magnitude = magnitude.parse::<i32>().expect("Not a valid number");
                if direction == "L" {
                    current_val -= magnitude;
                }
                if direction == "R" {
                    current_val += magnitude;
                }
    
                while current_val >= upper_limit {
                    current_val -= upper_limit;
                    temp_passes += 1;
                    if current_val == 0 {
                        temp_passes -= 1;
                    }
                }
                if current_val < lower_limit {
                    if original_val == 0 {
                        temp_passes -= 1;
                    }
                    while current_val < lower_limit {
                        current_val += upper_limit;
                        temp_passes += 1;
                    }
                }
                if current_val == 0 {
                    temp_stops += 1;
                }
                zero_passes += temp_passes;
                zero_stops += temp_stops;
                println!(
                    "The dial is rotated {direction} {magnitude} to point at {current_val}; during this rotation, it points at zero {temp_passes} times. It stopped at zero {temp_stops} additional times."
                );
            }
        } else {
            println!("Error reading input file");
        }
        let total = zero_passes + zero_stops;
        println!("Zero Stops: {zero_stops}, Zero Passes: {zero_passes}, Total: {total}");
        let elapsed = now.elapsed();
        println!("Elapsed: {:.2?}", elapsed);
    }
    
    fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
    where
        P: AsRef<Path>,
    {
        let file = File::open(filename)?;
        Ok(io::BufReader::new(file).lines())
    }
    
    1 vote
  11. Comment on Day 2: Gift Shop in ~comp.advent_of_code

    DeaconBlue
    Link
    I am pretty happy with my solution on this one. Early breaking when I see a failure gets this down to ~300ms on my laptop. I am absolutely sure the same algorithm could be done in a better way if...

    I am pretty happy with my solution on this one. Early breaking when I see a failure gets this down to ~300ms on my laptop. I am absolutely sure the same algorithm could be done in a better way if I knew Rust better.

    I only have the Part 2 solution because I changed the function call to do the whole thing, not thinking about holding both parts.

    Part 2
    use std::{
        env,
        fs::File,
        i32,
        io::{self, BufRead},
        path::Path,
        time::Instant,
    };
    
    fn main() {
        let now = Instant::now();
        let args: Vec<String> = env::args().collect();
        let mut total_invalid: i64 = 0;
        if let Ok(lines) = read_lines(&args[1]) {
            for line in lines {
                line.expect("")
                    .split(',')
                    .for_each(|x| total_invalid += add_range(x));
            }
        }
        println!("Total invalid: {total_invalid}");
        let elapsed = now.elapsed();
        println!("Elapsed: {:.2?}", elapsed);
    }
    fn add_range(range: &str) -> i64 {
        println!("{range}");
        let range = get_bounds(range);
        let mut temp_total = 0;
        for n in range.0..=range.1 {
            if is_invalid(n) {
                temp_total = temp_total + n;
            }
        }
        return temp_total;
    }
    
    fn get_bounds(bounds: &str) -> (i64, i64) {
        let mut split = bounds.split("-");
        let lower = split
            .next()
            .expect("")
            .parse::<i64>()
            .expect("Parsing Error");
        let higher = split
            .next()
            .expect("")
            .parse::<i64>()
            .expect("Parsing Error");
    
        return (lower, higher);
    }
    fn is_invalid(id: i64) -> bool {
        let id = id.to_string();
        let id_length = id.len();
        for n in 1..=id_length / 2 {
            let mut is_matching = id_length % n == 0;
            let split = id.split_at(n);
            let mut to_check = split.1;
            let mut index = 0;
            let max_index = to_check.len() / n;
            while is_matching && index < max_index {
                let chunks = to_check.split_at(n);
                is_matching = split.0 == chunks.0;
                to_check = chunks.1;
                index += 1;
            }
            if is_matching {
                println!("{id}");
                return true;
            }
        }
        return false;
    }
    
    fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
    where
        P: AsRef<Path>,
    {
        let file = File::open(filename)?;
        Ok(io::BufReader::new(file).lines())
    }
    
    1 vote
  12. Comment on Uber and Lyft prices vary for the same rides in ~transport

    DeaconBlue
    Link Parent
    I'll count myself in that 16% I don't do rideshare things generally. If I do, it's on a work trip where I am reimbursed for the money spent on them and I'm not spending my time toggling between...

    I'll count myself in that 16%

    I don't do rideshare things generally.

    If I do, it's on a work trip where I am reimbursed for the money spent on them and I'm not spending my time toggling between apps to save the company a couple of dollars on a trip that I don't want to be on in the first place. I ask the company what app they want me to use and just go with whatever they say.

    9 votes
  13. Comment on Over 120,000 home cameras hacked for 'sexploitation' footage in ~tech

    DeaconBlue
    Link
    My parents thought I was in tinfoil hat territory when my first was born and I declined a baby monitor that they bought that only worked online. This sucks for all of these victims. So many lives...

    My parents thought I was in tinfoil hat territory when my first was born and I declined a baby monitor that they bought that only worked online.

    This sucks for all of these victims. So many lives messed up, even if hopefully temporarily, for what a quick search says is less than an average year's salary.

    34 votes
  14. Comment on US shoppers, drawn by steep discounts, power through Black Friday in ~finance

    DeaconBlue
    Link
    My total Black Friday spending was $12 on a pizza. There is nothing I wanted less than to make my way through crowds of people or deal with online retailers. Thank you, everyone else, for spending...

    My total Black Friday spending was $12 on a pizza. There is nothing I wanted less than to make my way through crowds of people or deal with online retailers.

    Thank you, everyone else, for spending on my behalf!

    20 votes
  15. Comment on Advice request: potentially adopting a cat in ~life.pets

    DeaconBlue
    Link Parent
    Tell that to my cat that pushes scratchers out of the way to access the couch

    A tall scratching post near each corner or a long cardboard scratcher are good options generally. Importantly, if you see them scratch an object you don't want them to scratch, put an alternative at or near that location instead.

    Tell that to my cat that pushes scratchers out of the way to access the couch

    1 vote
  16. Comment on Are there any current Kagi extended trial codes? in ~tech

    DeaconBlue
    Link Parent
    I got some yesterday so I would expect to see them soon.

    I got some yesterday so I would expect to see them soon.

    1 vote
  17. Comment on Can I hope to defeat telematics in a new car? in ~transport

    DeaconBlue
    Link Parent
    The most frustrating conversation. My parents live out in the middle of nowhere so that they have privacy from neighbors just watching them all the time, and still say this when I talk about...

    the other part is that every time this gets asked in forums or subreddits dedicated to the car most of the responses are suggesting OP wears a tin foil hat or is a criminal.

    The most frustrating conversation.

    My parents live out in the middle of nowhere so that they have privacy from neighbors just watching them all the time, and still say this when I talk about blocking telemetry on my devices. They don't see a parallel and I do not get it.

    8 votes
  18. Comment on So, NPR fixed their RSS ... it seems to work globally again in ~tech

    DeaconBlue
    Link Parent
    You may also want to consider 418 if you are looking to be silly to crawlers.

    You may also want to consider 418 if you are looking to be silly to crawlers.

    1 vote
  19. Comment on So, NPR fixed their RSS ... it seems to work globally again in ~tech

    DeaconBlue
    Link
    Your best guess is likely correct. The controller for the RSS feed likely was intertwined with some other controller that was geoblocked, or the services were behind the same "Front Door" style...

    Your best guess is likely correct. The controller for the RSS feed likely was intertwined with some other controller that was geoblocked, or the services were behind the same "Front Door" style handler, and the requests started getting blocked in the same way.

    On a related note, I really wish geoblocking (and most things, actually) responded with the correct error codes. Almost everything returns a 404 Not Found when it should be like 403 for a permissions issue or 451 (lol get it?) when the content is blocked by local laws or geoblocked.

    17 votes
  20. Comment on Strange YouTube watch-tracking behavior in ~tech

    DeaconBlue
    Link Parent
    The most infuriating part of this is that the videos are not quite on a grid, so moving the pointer between videos and scrolling down is not enough, as it might start auto playing something on the...

    The most infuriating part of this is that the videos are not quite on a grid, so moving the pointer between videos and scrolling down is not enough, as it might start auto playing something on the next row.

    3 votes