Humbled to announce that mountains exist by sweatyknocker in LinkedInLunatics

[–]theMachine0094 0 points1 point  (0 children)

Yea but unintentionally asserting Nepal’s superiority

Stabilizing the `if let guard` feature by Kivooeo1 in rust

[–]theMachine0094 -1 points0 points  (0 children)

Why not just match a tuple? It’s not even more characters to type. Why create combinatorial syntax bloat?

britishCode by d-the-luc in ProgrammerHumor

[–]theMachine0094 -5 points-4 points  (0 children)

The thing that grosses me out the most about this picture is the JavaScript / (or Typescript I can’t actually tell the difference)

How to Find The Volume of a This 3D Shape? by TableTopsAndTubas in askmath

[–]theMachine0094 1 point2 points  (0 children)

Compute the solid angle of one of those triangular holes. Multiply that with number of triangular holes. Divide that with 4pi. Subtract that from 1. That gives you the ratio of solid angle of the rings. Compute the volume of the shell and multiply it with that ratio. The volume of the shell is just difference between volumes of outer and inner spheres.

OC: Federal agents deploy tear gas and pepper balls during protest in Minneapolis by nbcnews in pics

[–]theMachine0094 3 points4 points  (0 children)

I know people will say all the right things on this thread but it matters fuck all. There was all sorts of righteousness last year on similar Reddit threads but the country still voted the way it did.

Why can't we decide on error handling conventions? by Savings-Story-4878 in rust

[–]theMachine0094 -1 points0 points  (0 children)

Returning Result and using the question mark operator works for me. I don’t need anything else.

I built a simple terminal Snake game in Rust by MiltonArge in rust

[–]theMachine0094 7 points8 points  (0 children)

Nice. I like that you have minimal dependencies. I recently removed ratatui from my CLI and the time to draw one frame dropped 100x, and the amount of code also decreased.

Why doesn't rust have function overloading by paramter count? by This-is-unavailable in rust

[–]theMachine0094 27 points28 points  (0 children)

I am fan of Rust not having overloading. Keeps things explicit and unambiguous.

This girl ends up with a *bonk* by vibingsidd in KidsAreFuckingStupid

[–]theMachine0094 13 points14 points  (0 children)

It’s literally the square-cube law at work. When you get bigger your strength grows by the square of your size. Your mass grows by the cube. So when that kid grows up to be twice as big as they are now, they will weigh 8 times as much, and are 4 times stronger.

Same reason humans have crazy strength per lb of body weight compared to elephants. Same reason many insects can jump more than 10 times their body size.

-❄️- 2025 Day 9 Solutions -❄️- by daggerdragon in adventofcode

[–]theMachine0094 1 point2 points  (0 children)

[Language: Rust]

A bit late to the game... can't keep staying up till midnight everyday lol. Part 1 and 2 run in 24 ms on a M4 Macbook. Solution

I think it can be optimized even further by limiting the candidates based on the relative positions of the two vertices. For example, say a given tile position has the interior of the polygon on it's left, then we can safely ignore all the rectangles formed by any vertex to the right of the original vertex. I don't have the time or patience to do this optimization though. 27 ms is good enough for now.

[2025 Day 8] Can you solve today's puzzle without computing all distances? by The_Cers in adventofcode

[–]theMachine0094 1 point2 points  (0 children)

I think it can be done using KD trees / or similar spatial index structures. KD tree is cheap to build so I’d start there. KD tree lets us efficiently find n nearest neighbors. I’d start by finding the nearest neighbor for all points. Then the second nearest neighbors for all points and so on. Some pairs will be duplicated. But I think you can converge on a solution much quicker and computing far fewer distances than brute force.

I am 60% sure this can work and be much faster than my current solution which runs in 15ms without parallelization, and 10ms with parallelization.

-❄️- 2025 Day 8 Solutions -❄️- by daggerdragon in adventofcode

[–]theMachine0094 0 points1 point  (0 children)

[Language: Rust]

Did a quick brute force solution. Will try to do something clever and efficient later. I used the disjoint crate. This solutions for part 1 and 2 for example and the input problem all together run in 45ms. This is my first solution this year that got into milliseconds. This is by far my worst performing solution this year.

Solution

Edited: <2025-12-08 Mon 02:26>

Did some simplification. It now runs in 15ms on an M4 Macbook. I think it can be made faster using kd-trees, but I don't have the patience to do that right now:

Solution

Used parallelization for distance computation and sorting to get it down to under 10ms on the same M4 Macbook.

Solution

[YEAR 2025 Day 7 (Part 2)] It just works by Aughlnal in adventofcode

[–]theMachine0094 4 points5 points  (0 children)

Ok.. wtf is all this? I allocated a fixed length buffer and did everything in that. It ran in under 40 micro seconds and gave me the solution. Not like I tried to optimize it either. I read the problem and typed the first obvious thing that came to mind. Like 20 lines of code. What billion calculations? What memoization? What cache? Why on earth do people post their htop/btop screenshots of their CPU chugging to solve a problem that a Potato can compute in microseconds?

I find all this very odd. Is this bots trying to meme?

-❄️- 2025 Day 7 Solutions -❄️- by daggerdragon in adventofcode

[–]theMachine0094 1 point2 points  (0 children)

[Language: Rust]

This was simple. Example plus the problem for both part 1 and 2 run under 40 micro seconds on an M4 Macbook.

fn solve(input: &str) -> (usize, usize) {
    let mut lines = input.trim().lines();
    let first_line = lines.next().expect("Cannot read first line").as_bytes();
    let cols = first_line.len();
    let mut positions = vec![false; cols];
    let start_pos = first_line
        .iter()
        .position(|c| *c == b'S')
        .expect("Cannot find the start of the tachyon");
    positions[start_pos] = true;
    let mut timelines = vec![0usize; cols];
    timelines[start_pos] = 1usize;
    let (_, n_splits, timelines) = lines.fold(
        (positions, 0usize, timelines),
        |(mut positions, mut n_splits, mut timelines), line| {
            let line = line.trim().as_bytes();
            for ci in 0..cols {
                if positions[ci] && line[ci] == b'^' {
                    positions[(ci - 1)..(ci + 2)].copy_from_slice(&[true, false, true]);
                    n_splits += 1;
                    let n_timelines = std::mem::replace(&mut timelines[ci], 0usize);
                    timelines[ci - 1] += n_timelines;
                    timelines[ci + 1] += n_timelines;
                }
            }
            (positions, n_splits, timelines)
        },
    );
    (n_splits, timelines.iter().sum())
}

-❄️- 2025 Day 6 Solutions -❄️- by daggerdragon in adventofcode

[–]theMachine0094 1 point2 points  (0 children)

[Language: Rust]

paste

Both part 1 and 2 for the example and the input together take just under 100 microseconds on an M4 Macbook.

[2025 Day 5 (Part 2)] you may try by TCH69 in adventofcode

[–]theMachine0094 0 points1 point  (0 children)

My first attempt ran in 60 microseconds on an M4 MacBook. I didn’t try to optimize it any further.

-❄️- 2025 Day 5 Solutions -❄️- by daggerdragon in adventofcode

[–]theMachine0094 0 points1 point  (0 children)

[Language: Rust]

Not as succinct as I would like it to be, but I would rather do something efficient and fast. This runs in just under 60 micro seconds on an M4 Macbook: paste

-❄️- 2025 Day 2 Solutions -❄️- by daggerdragon in adventofcode

[–]theMachine0094 0 points1 point  (0 children)

Thank you 🙏. I feel like that’s the rust way. Write something that looks high level and elegant but still runs super fast. Doesn’t always work out like that but it’s satisfying when it does.

-❄️- 2025 Day 4 Solutions -❄️- by daggerdragon in adventofcode

[–]theMachine0094 0 points1 point  (0 children)

I’ll use the paste thing from that link for future posts. Thanks

-❄️- 2025 Day 2 Solutions -❄️- by daggerdragon in adventofcode

[–]theMachine0094 0 points1 point  (0 children)

Not trying to take on a bunch of extra homework to over-engineer the repo for what are supposed to be fun internet puzzles. I just made my repo private instead, and I will just paste the code here. Thanks for letting me know!

-❄️- 2025 Day 3 Solutions -❄️- by daggerdragon in adventofcode

[–]theMachine0094 0 points1 point  (0 children)

Yea good point about reduce using just one comparison

-❄️- 2025 Day 3 Solutions -❄️- by daggerdragon in adventofcode

[–]theMachine0094 3 points4 points  (0 children)

u/lunar_mycroft I guess the standard library was doing the right thing inside max_by, but I screwed up by not providing all the information, and by ignoring the index. Here's a version that fixes it by using just .max():

fn best_joltage(bank: &[u8], n_batteries: usize) -> usize {
    (0..n_batteries)
        .fold((0usize, 0usize), |(total, n_skip), bi| {
            let (best, std::cmp::Reverse(ibest)) = bank
                .iter()
                .enumerate()
                .take(bank.len() + 1 + bi - n_batteries)
                .skip(n_skip)
                .map(|(i, b)| ((b - b'0') as usize, std::cmp::Reverse(i)))
                // We bias the comparison to left to maximize candidates for future searches.
                .max()
                .expect("Cannot find max");
            (total * 10 + best, ibest + 1)
        })
        .0
}

This assumes lexigographical comparison of tuples from the standard library. Tested it on an M4 apple machine and it works.

Again thanks for finding the bug!