Skip Navigation

InitialsDiceBearhttps://github.com/dicebear/dicebearhttps://creativecommons.org/publicdomain/zero/1.0/„Initials” (https://github.com/dicebear/dicebear) by „DiceBear”, licensed under „CC0 1.0” (https://creativecommons.org/publicdomain/zero/1.0/)H
Posts
22
Comments
60
Joined
11 mo. ago

  • Welcome to Rust, I hope you enjoyed learning and using it :)

    One major advice would be to run cargo clippy, which gives a lot of helpful hints. Apart from that I also have some feedback.

     
        
        40	struct VendorOuiData {
        41	    vendor_organization: String, // Vendor Organization
    
      

    These comments should be doc-comments (///) so that cargo doc picks them up.

     
        
        49	fn fetch_oui_database(url_string: &String) -> Result<String, Box<dyn std::error::Error>> {
    
      

    Not saying that your return type is bad, but in general you might be interested in crates thiserror and anyhow that simplify error handling.

     
        
        51	        .timeout(Duration::new(60, 0))
    
      

    Duration::from_mins(1) would be much more readable.

     
        
        66	                panic!("{}", err);
    
      

    You should almost never panic. Your function already returns a Result<>, so you should be using that for error handling.

     
        
        70	    } else {
        71	        // HTTP Status is not 200
    
      

    Not Rust specific, but usually I recommend to handle errors first, and return from the function early. This way you reduce cognitive load on the reader, and reduce nesting of if-blocks.

     
        
       150	                let mut parts = line.splitn(2, '\t');
    
      

    There's a convenient method to split in two substrings that you could have used:

     
        
    let (mac_address, vendor_organization) = line.split_once('\t').unwrap_or(("", ""));
    
      

     
        
       166	                vendor_oui_data.vendor_address += line
       167	                    .trim()
       168	                    .split(' ')
       169	                    .filter(|s| !s.is_empty())
       170	                    .collect::<Vec<_>>()
       171	                    .join(" ")
       172	                    .as_str();
    
      

    I would probably write a regular expression that replaces all contiguous whitespace with a single space instead.

     
        
       173	                vendor_oui_data.vendor_address.push('\n');
    
      

    Aren't you trimming this new line off in line 181?

     
        
       181	        vendor_oui_data.vendor_address = vendor_oui_data.vendor_address.trim().to_string();
    
      

    This is somewhat inefficient, since you'll be allocating and copying your string here.

  • That’s a very interesting thought! I was thinking of writing my own Rust data type that would automatically upgrade to big integer, similarly to the int type in Python.

  • Christmas, I guess :) (I just pick a random colour each time a roll is removed)

  • That's day 7, right?

  • Apart from day 4 not much to visualise so far this year :/

  • it all fit in int64 tho, so could be worse

  •  
        
    constexpr u32 TEN = 10;
    constexpr u64 TWELVE = 12;
    
      

    I love the easter egg jokes you add to your code :)

  • Computer science is just mathematics, you can do it with pen and paper. The actual IT jobs where you don't have to touch windows are plentiful, although it might be a bit of a red flag if you're vehemently refusing to touch some specific software (be it windows, or any other program, or programming language).

  • so many years have passed since i last wrote a line of masm...

  • ah that’s just because i needed rounding towards infinity and not towards zero. In other words i wanted -10/100 to be -1 and not zero. But i couldn’t figure it out on the spot, so i just made it never negative :)

  • Thanks! I don’t mind tips at all.

  • the idea is that crossing the zero is easy to detect by dividing the total dial movement by 100. I.e. if you cross from 120 to 90 you will detect that 120/100=1 changed to 90/100=0. The only case when this doesn’t work is when you stop at zero going in the negative direction, hence the extra if

  • Rust

     
        
    #[derive(Default)]
    pub struct Day1Solver {
        input: Vec<i64>,
    }
    
    impl Solver for Day1Solver {
        fn presolve(&mut self, input: &str) {
            self.input = input
                .trim()
                .split("\n")
                .map(|line| {
                    if let Some(n) = line.strip_prefix('L') {
                        -n.parse::<i64>().unwrap()
                    } else if let Some(n) = line.strip_prefix('R') {
                        n.parse().unwrap()
                    } else {
                        panic!("what: {line}");
                    }
                })
                .collect();
        }
    
        fn solve_part_one(&mut self) -> String {
            let mut p = 50;
            let mut count = 0;
            for n in self.input.clone() {
                p += n;
                if p % 100 == 0 {
                    count += 1;
                }
            }
            count.to_string()
        }
    
        fn solve_part_two(&mut self) -> String {
            let mut count = 0;
            let mut p = 1000000000050;
            for i in self.input.clone() {
                if p % 100 == 0 {
                    count += (i / 100).abs();
                } else {
                    count += ((p + i) / 100 - p / 100).abs();
                    if i < 0 && (p + i) % 100 == 0 {
                        count += 1;
                    }
                }
                p += i;
            }
            count.to_string()
        }
    }
    
      
  • It uses Gemini on web or else it gets the hose again.

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 20 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 19 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 18 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 17 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 16 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 15 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 14 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 13 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 12 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 11 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 10 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 9 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 8 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 7 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 6 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 5 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 4 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 3 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 2 Solutions 🦆

  • Advent Of Code @programming.dev

    🦆 Everybody.Codes 2025 Quest 1 Solutions 🦆