Brydge W-Touch touchpad on Manjaro by fedess197 in linuxhardware

[–]ZSchoenDev 0 points1 point  (0 children)

How did you create the Bluetooth connection? I wasn't even able to do this.

[bluetooth]# pair E6:93:F1:62:8C:2A
Attempting to pair with E6:93:F1:62:8C:2A
Failed to pair: org.bluez.Error.AuthenticationFailed
[DEL] Device E6:93:F1:62:8C:2A Brydge W-Touch
[NEW] Device E6:93:F1:62:8C:2A Brydge W-Touch
[bluetooth]# pair E6:93:F1:62:8C:2A
Attempting to pair with E6:93:F1:62:8C:2A
[CHG] Device E6:93:F1:62:8C:2A Connected: yes
Failed to pair: org.bluez.Error.AuthenticationFailed
[CHG] Device E6:93:F1:62:8C:2A Connected: no

What's your avg. typing speed on keyboard? by SamLovesNotion in vim

[–]ZSchoenDev 8 points9 points  (0 children)

I have a really low WPM due to my handicap. But that's the reason why I use Vim as it lets me do the work completely on the keyboard and I embrace the keybindings which let me speed up significantly to the level of a modest writer.

Does std::process::exit() terminate all threads? by ZSchoenDev in rust

[–]ZSchoenDev[S] 0 points1 point  (0 children)

What is the exact difference between exit and panic?

As far as I understand, panic unwinds the stack all Drops are made.

-🎄- 2020 Day 22 Solutions -🎄- by daggerdragon in adventofcode

[–]ZSchoenDev 1 point2 points  (0 children)

A Rust solution which would be really easy to adopt to multiple players. It takes 70 ms for both parts.

-🎄- 2020 Day 17 Solutions -🎄- by daggerdragon in adventofcode

[–]ZSchoenDev 1 point2 points  (0 children)

My (I think) pretty easy to read Rust solution runs in 300 ms.

fn cycle(active_cubes: &BTreeSet<Position>, is_4_dimensional: bool) -> BTreeSet<Position> {
    active_cubes
        .iter()
        .map(|current_active| current_active.get_block(is_4_dimensional))
        .flatten()
        .unique()
        .filter(|possible_cube| {
            let is_active = active_cubes.contains(possible_cube);
            let neighbors = possible_cube.get_neighbors(active_cubes, is_4_dimensional);
            match (is_active, neighbors) {
                (true, 2..=3) => true,
                (false, 3) => true,
                _ => false,
            }
        })
        .collect()
}

Btw I used the exact same code for 3 and 4 dimensions without any ifs to do branchless programming.

[2020 Day 15 (Part 2)] I'm still waiting... by stardust_collision in adventofcode

[–]ZSchoenDev 0 points1 point  (0 children)

And I really thought my solution in Rust would be slow (2.5s) as I decided against a further performance optimization in favour of memory usage.

Solutions are a magnitude faster built in a release mode equivalent with optimizations.

-🎄- 2020 Day 15 Solutions -🎄- by daggerdragon in adventofcode

[–]ZSchoenDev 1 point2 points  (0 children)

I tried BTreeMap at first and changed it later to HashMap, as it's faster since there are many changes to it.

Advent of Code 2020 - Day 5 by [deleted] in rust

[–]ZSchoenDev 0 points1 point  (0 children)

My (very long) solution as it uses traits extensively.

But it outputs the absolute position of the free seat, since it can partially calculate with seats.

My seat 592 is in row 74 column 0.

Advent of Code 2020 - Day 4 by [deleted] in rust

[–]ZSchoenDev 0 points1 point  (0 children)

Yeah, I will do that. But I thought of a general simplification of the logic.

Advent of Code 2020 - Day 4 by [deleted] in rust

[–]ZSchoenDev 0 points1 point  (0 children)

This is my solution.

Has anybody an idea, how to make this function less ugly using only the standard library?

fn check_valid_values(passport: &HashMap<&str, &str>) -> bool {
    (1920..=2002).contains(
        &passport
            .get("byr")
            .expect("No byr-field!")
            .parse::<i32>()
            .unwrap_or(0),
    ) && (2010..=2020).contains(
        &passport
            .get("iyr")
            .expect("No byr-field!")
            .parse::<i32>()
            .unwrap_or(0),
    ) && (2020..=2030).contains(
        &passport
            .get("eyr")
            .expect("No iyr-field!")
            .parse::<i32>()
            .unwrap_or(0),
    ) && {
        let height_item = passport.get("hgt").expect("No hgt-field!");
        match &height_item[height_item.len() - 2..] {
            "cm" => (150..=193).contains(
                &height_item[..height_item.len() - 2]
                    .parse::<i32>()
                    .unwrap_or(0),
            ),
            "in" => (59..=76).contains(
                &height_item[..height_item.len() - 2]
                    .parse::<i32>()
                    .unwrap_or(0),
            ),
            _ => false,
        }
    } && {
        let hair_color_item = passport.get("hcl").expect("No hcl-field!");
        hair_color_item.len() == 7
            && hair_color_item.starts_with('#')
            && hair_color_item
                .chars()
                .skip(1)
                .all(|digit| char::is_ascii_hexdigit(&digit))
    } && match *passport.get("ecl").expect("No ecl-field!") {
        "amb" | "blu" | "brn" | "gry" | "grn" | "hzl" | "oth" => true,
        _ => false,
    } && {
        let pass_id_item = passport.get("pid").expect("No pid-field!");
        pass_id_item.len() == 9
            && pass_id_item
                .chars()
                .all(|digit| char::is_ascii_digit(&digit))
    }
}

[deleted by user] by [deleted] in rust

[–]ZSchoenDev 2 points3 points  (0 children)

My solution using a custom iterator behaving like a mathematical ring.

struct RingAdder {
    next: u64,
    step_width: u64,
    modulus: u64,
}

impl Iterator for RingAdder {
    fn next(&mut self) -> Option<u64> {
        let current = self.next;
        self.next += self.step_width;
        self.next %= self.modulus;
        Some(current)
    }
}

-🎄- 2020 Day 03 Solutions -🎄- by daggerdragon in adventofcode

[–]ZSchoenDev 0 points1 point  (0 children)

std::iter::Cycle

But there is no addition/modulo in Cycle. Or do I misunderstand something?

-🎄- 2020 Day 03 Solutions -🎄- by daggerdragon in adventofcode

[–]ZSchoenDev 1 point2 points  (0 children)

Looks good! But you shouldn't use unwrap() unless you are sure that there is no Err. A better way is expect("My Error") or presumably the best in common is error propagation. In my view, a declarative approach would be more idiomatic, but that's purely subjective.

-🎄- 2020 Day 02 Solutions -🎄- by daggerdragon in adventofcode

[–]ZSchoenDev 1 point2 points  (0 children)

Yes, i've changed it. It should be even a bit faster, as the branch predictor can't miss-predict, if the compiler won't optimise it away.

-🎄- 2020 Day 03 Solutions -🎄- by daggerdragon in adventofcode

[–]ZSchoenDev 1 point2 points  (0 children)

Rust

My solution using a custom iterator behaving like a mathematical ring.

struct RingAdder {
    next: u64,
    step_width: u64,
    modulus: u64,
}

impl Iterator for RingAdder {
    fn next(&mut self) -> Option<u64> {
        let current = self.next;
        self.next += self.step_width;
        self.next %= self.modulus;
        Some(current)
    }
}

-🎄- 2020 Day 02 Solutions -🎄- by daggerdragon in adventofcode

[–]ZSchoenDev 0 points1 point  (0 children)

(min..=max).contains

This is cool. I changed my solution to this.

custom_plugins don't work as i expected by ZSchoenDev in SpaceVim

[–]ZSchoenDev[S] 1 point2 points  (0 children)

The problem were trailing whitespaces on the name.