Treeniks

joined 1 year ago
[โ€“] [email protected] 4 points 10 months ago

I have night light turned on 24/7 on all my devices. If I don't I get a headache after around a day.

In fact, I couldn't consistently use linux until recently because only the latest Nvidia drivers (545) added support for night light on wayland. Those glasses could've been handy there.

[โ€“] [email protected] 1 points 10 months ago* (last edited 10 months ago) (1 children)

Rust

github codeberg gitlab

First tried a really slow brute force, but after waiting many minutes heard others talk of Karger's Algorithm, so I implemented that.

use rand::prelude::*;
use std::collections::HashSet;

type Graph = (V, E);

type V = HashSet<String>;
type E = Vec<(String, String)>;

fn parse_input(input: &str) -> Graph {
    let mut vertices = HashSet::new();
    let mut edges = Vec::new();

    for line in input.trim().lines() {
        let mut it = line.split(':');

        let left = it.next().unwrap();
        vertices.insert(left.to_owned());

        for right in it.next().unwrap().trim().split_whitespace() {
            vertices.insert(right.to_owned());
            edges.push((left.to_owned(), right.to_owned()));
        }
    }

    (vertices, edges)
}

fn part1(input: &str) -> usize {
    let (vertices, edges) = parse_input(input);

    let mut rng = rand::thread_rng();

    // Karger's Algorithm
    loop {
        let mut vertices = vertices.clone();
        let mut edges = edges.clone();
        while vertices.len() > 2 {
            let i = rng.gen_range(0..edges.len());
            let (v1, v2) = edges[i].clone();

            // contract the edge
            edges.swap_remove(i);
            vertices.remove(&v1);
            vertices.remove(&v2);

            let new_v = format!("{}:{}", v1, v2);
            vertices.insert(new_v.clone());

            for (e1, e2) in edges.iter_mut() {
                if *e1 == v1 || *e1 == v2 {
                    *e1 = new_v.clone()
                }
                if *e2 == v1 || *e2 == v2 {
                    *e2 = new_v.clone()
                }
            }

            // remove loops
            let mut j = 0;
            while j < edges.len() {
                let (e1, e2) = &edges[j];
                if e1 == e2 {
                    edges.swap_remove(j);
                } else {
                    j += 1;
                }
            }
        }

        if edges.len() == 3 {
            break vertices
                .iter()
                .map(|s| s.split(':').count())
                .product::<usize>();
        }
    }
}
[โ€“] [email protected] 2 points 10 months ago

Rust

github: https://github.com/Treeniks/advent-of-code/blob/master/2023/day24/rust/src/main.rs

codeberg: https://codeberg.org/Treeniks/advent-of-code/src/branch/master/2023/day24/rust/src/main.rs

gitlab: https://gitlab.com/Treeniks/advent-of-code/-/blob/master/2023/day24/rust/src/main.rs

Had to look on reddit for how to solve part 2. Wasn't happy with the idea of using something like Z3, so I ended up brute force guessing the velocity, solving for the position and time and seeing if those are correct.

Lots of unintelligible calculations for solving the equation systems in the code that I just prepared on paper and transferred over.

[โ€“] [email protected] 14 points 11 months ago

This is correct, while OpenGL and DirectX 11 and before are considered high level APIs, Vulkan and DirectX 12 are both considered low level APIs.

[โ€“] [email protected] 1 points 11 months ago* (last edited 11 months ago)

Zig

https://github.com/Treeniks/advent-of-code/blob/master/2023/day22/zig/src/main.zig

(or on codeberg if you don't like to use github: https://codeberg.org/Treeniks/advent-of-code/src/branch/master/2023/day22/zig/src/main.zig )

Every time I use Zig, I love the result, but I hate writing it. The language is just a little too inflexible for quick and dirty solutions to quickly try out an idea or debug print something useful, but once you're done and have a result, it feels quite complete.

[โ€“] [email protected] 4 points 11 months ago (2 children)

Rust

https://github.com/Treeniks/advent-of-code/blob/master/2023/day21/rust/src/main.rs

I reused my Grid struct from day 17 for part 1, just to realize that I'll need to expand the grid for part 2 so I awkwardly hacked it to be a Vec<Vec<Tile>> instead of a linear Vec<Tile>.

I solved task 2 by reading through the reddit thread and trying to puzzle together what I was supposed to do. Took me a while to figure it out, even with literally looking at other people's solutions. I wrote a lengthy comment about it for anyone that's still struggling, but I honestly still don't really understand why it works. I think I wouldn't have solved it if I didn't end up looking at other solutions. Not a fan of the "analyze the input and notice patterns in them" puzzles.

[โ€“] [email protected] 2 points 11 months ago (1 children)
[โ€“] [email protected] 1 points 11 months ago* (last edited 11 months ago) (1 children)

I'm a little confused about this one. The mappings are total, that is any number that is not defined explicitly gets mapped to itself. So it's easy to create an example where the lowest number does not get mentioned within a range:

seeds: 0 3

seed-to-soil map:
10 0 2

soil-to-fertilizer map:
100 200 5

fertilizer-to-water map:
100 200 5

water-to-light map:
100 200 5

light-to-temperature map:
100 200 5

temperature-to-humidity map:
100 200 5

humidity-to-location map:
100 200 5

Here, we have seeds 0, 1 and 2. seed 0 gets mapped to location 10, seed 1 gets mapped to location 11 and seed 2 gets mapped to location 2. That means location 2 would be the answer, but it's not a start of any range. I guess this just doesn't happen in any of the inputs?

EDIT: actually it's double weird. If you implemented a backwards search, that is you create reverse mappings and then try out all locations (which is what I and many others did), the result of the above example is location 0, whereas if you create a forwards brute force of all seeds, the result is 2. For the reverse approach to work in all cases, the mappings would have to be bijective.

[โ€“] [email protected] 61 points 1 year ago (7 children)

tbf that's a lot easier to say when you're the president of one of the richest companies in the industry. I don't disagree, but not everybody has the resources to just keep developing forever, and that's easy to forget too.

[โ€“] [email protected] 4 points 1 year ago

The only feature I miss in the Epic client is a way to make yourself appear as offline. Other than that, Steam has a bunch of social features that I couldn't care less about.

[โ€“] [email protected] 8 points 1 year ago (1 children)

I'm aware of nautilus-admin, but not only is it not maintained, imho it should be part of nautilus by default, and it has to open a new nautilus window when you use it. What I want is to drag and drop files to /usr/local and then get a password prompt to do the move. With nautilus-admin, I need to have the foresight to use "Open as admin" when going into /usr/local, but if I had that foresight then I might as well just start nautilus as root to begin with. Usually I just want to look into the folder, and only then realize I need to change something, which means a good old "go back up one folder, then search the local folder again, then right click, search for 'Open as admin', then get thrown into a new window, completely disorienting myself in the process".

view more: โ€น prev next โ€บ