[–] 67 points 11 months ago

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).

  • source
  • [–] 2 points 11 months ago

    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 :)

  • source
  • parent
  • context
  • [–] 3 points 11 months ago (2 children)

    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

  • source
  • parent
  • context
  • [–] 5 points 11 months ago (8 children)

    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()
        }
    }
    
  • source
  •  

    Quest 8: The Art of Connection

    • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
    • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

    Link to participate: https://everybody.codes/

     

    Quest 7: Namegraph

    • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
    • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

    Link to participate: https://everybody.codes/

     

    Quest 6: Mentorship Matrix

    • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
    • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

    Link to participate: https://everybody.codes/

     

    Quest 5: Fishbone Order

    • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
    • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

    Link to participate: https://everybody.codes/

     

    Quest 4: Teeth of the Wind

    • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
    • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

    Link to participate: https://everybody.codes/

     

    Quest 3: The Deepest Fit

    • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
    • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

    Link to participate: https://everybody.codes/

    Also, don't wait for me to make these posts, feel free to post yourself :)

     

    Quest 2: From Complex to Clarity

    • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
    • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

    Link to participate: https://everybody.codes/

     

    Quest 1: Whispers in the Shell

    • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
    • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

    Link to participate: https://everybody.codes/

     

    I was solving old Advent of Code the other day, and someone suggested to me another seasonal coding challenge website: https://everybody.codes/home

    As there are many people here who are actively solving AoC, I'm sure you'd be interested in that too. However, I'm not sure which community we should be using to discuss these? I'm seeing three options:

    • use this community for everybody.codes specifically (as it has largely the same format as AoC, and probably a lot of AoC solvers would be interested in that too),
    • create a dedicated community for everybody.codes (I can do that using this community as a blueprint),
    • use !challenges (the format doesn't really match, but in spirit it kinda makes sense).

    WDYT?

     

    If you were designing a standard library of a high level language (like Rust, C++, etc.) what would it do if while getting the current time of day (e.g. SystemTime::now()) it encountered a failed kernel system call (e.g. to clock_gettime) and why?

    What do you think the existing implementations do?

    • Return error or raise exception
    • Return 0
    • Return undefined values (like stack garbage)
    • Panic/crash/segfault
    view more: ‹ prev next ›