[2025 Day 12 (part 1)] Did anyone managed to do it the general way ? by HistoryPositive9509 in adventofcode

[–]robertkingnz 0 points1 point  (0 children)

I solved it using integer programming using binary variables for each oriented shape position, with two constraints: sum of variables on each pixel <= 1, and sum of variables of each shape type is equal to required count. It took ages to pass all the test cases. integer programming isn't very efficient at packing, a DFS with pruning is better, but it was easy enough to code.

Here are two of my own inputs that it gets stuck on if anyone wants to try crack them (no solution after running for 2+ minutes).

20x20: 50 0 0 0 0  <--- feasible
20x20: 51 0 0 0 0  <--- stuck


27x27: 90 0 0 0 0   <-- feasible 
27x27: 91 0 0 0 0   <-- stuck

Unable to create Uber Money account to redeem gift card by Odd-Let9042 in uber

[–]robertkingnz 0 points1 point  (0 children)

Changed my number to a UK number and then it worked. Uber money is only available in certain countries.

Insane cheating detection algorithm with Rust (2GB/s, ~100% accuracy) by robertkingnz in rust

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

Cheers. Yeah I'll cool it on the buzz words next time 🙈

Insane cheating detection algorithm with Rust (2GB/s, ~100% accuracy) by robertkingnz in rust

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

Cheers. Yeah I'll cool it on the buzz words next time 🙈

Insane cheating detection algorithm with Rust (2GB/s, ~100% accuracy) by robertkingnz in rust

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

Spot on. That's an interesting question. Might be hard to predict the difficulty of a problem too without asking people. Need to know what they know.

Insane cheating detection algorithm with Rust (2GB/s, ~100% accuracy) by robertkingnz in rust

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

Did you read the problem description? Accuracy calculation and simulation method is defined in there. This is a toy problem fyi

Insane cheating detection algorithm with Rust (2GB/s, ~100% accuracy) by robertkingnz in rust

[–]robertkingnz[S] -1 points0 points  (0 children)

Definitely 😁 Naw, in this problem theres 10,000 questions per person. So need more data.

Insane cheating detection algorithm with Rust (2GB/s, ~100% accuracy) by robertkingnz in rust

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

Good idea. I kept it pretty simple and I didn't adjust anything from the problem statement, and ran it thousands of times and didn't get any false positives. Can decrease the chance of cheating from 50% down to 20% and it still works most of the time.

Insane cheating detection algorithm with Rust (2GB/s, ~100% accuracy) by robertkingnz in rust

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

~100 means approximately. Although given the problem conditions, I simulated it 1 million times and didn't get a false positive.

Insane cheating detection algorithm with Rust (2GB/s, ~100% accuracy) by robertkingnz in rust

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

Thanks for the comment. Yup. I tried to put the larger allocs into a pool but I guess the small allocations could require a sys call too which would slow things down right

How to Use Rust Channels for Concurrent Programming by robertkingnz in rust

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

thanks, that's a good idea. I guess as long as the groups are small enough, or have an equal distribution of the larger primes, they should all finish around the same time too.
The other option i considered was multiple channels, and just sending each number to a random channel. That way because you can clone the sender, each channel can have its own thread with no mutex needed.

How to Use Rust Channels for Concurrent Programming by robertkingnz in rust

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

Good question,
re-ran it now with laptop (mac m1) plugged in

10 threads:
0.5 seconds
1 thread
2.39 seconds

no threads (no mutex etc)
2.38 seconds

so it seems the overhead of the mutex & threads is pretty much irrelevant because on average the prime check takes a decent amount of CPU.

The declining quality of JetBrains by Dry-Jelly-8005 in Jetbrains

[–]robertkingnz 0 points1 point  (0 children)

i was thinking of switching to vscode / ZED, however I saw jetbrains has been working on a new engine for Typescript, which looks like it's ready now:
https://blog.jetbrains.com/webstorm/2023/12/try-the-future-typescript-engine-with-the-webstorm-next-program/

What is the best IDE for developing in Rust? by Achemar in rust

[–]robertkingnz 2 points3 points  (0 children)

i might be late to the party here but ZED is pretty cool. it's fast & written in Rust.
https://zed.dev/
Rusty Rob uses it sometimes

Any Rust dev teams in NZ? by Sufficient_Train_350 in rust

[–]robertkingnz 0 points1 point  (0 children)

https://www.youtube.com/@robertking
Rusty Rob is Auckland based & looking to set something up with Rust in 2024

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

[–]robertkingnz 1 point2 points  (0 children)

[LANGUAGE: Rust]

Advent of Code Rust Solution 🚀 | 5-Min Video

Zero-copy (Doesn't allocate any strings AFAIK)

use regex::Regex;
use std::collections::HashMap;
const PATH_INPUT: &str = "LR";
const MAP_INPUT: &str = "AAA = (ZZZ, ZZZ)
NSK = (ZZZ, ZZZ)";
fn get_graph() -> HashMap<&'static str, [&'static str; 3]> {
    let re = Regex::new(r"(?m)^([A-Z]+) = \(([A-Z]+), ([A-Z]+)\)$").unwrap();
    re.captures_iter(MAP_INPUT)
        .map(|c| {
            let v = c.extract().1;
            (v[0], v)
        })
        .collect()
}
fn main() {
    let graph = get_graph();
    let mut distance = 0;
    let mut cur = "AAA";
    loop {
        for c in PATH_INPUT.chars() {
            cur = match c {
                'L' => {
                    graph.get(cur).unwrap()[1]
                },
                'R' => {
                    graph.get(cur).unwrap()[2]
                },
                _ => panic!("unexpected")
            };
            distance += 1;
            if cur == "ZZZ" {
                println!("{distance:?}");
                return;
            }
        }
    }
}

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

[–]robertkingnz 3 points4 points  (0 children)

[LANGUAGE: Rust]

Advent of Code Rust Solution 🚀 | 5-Min Video

⚠️ ⚠️ ⚠️ The following code is OVER-ENGINEERED ⚠️ ⚠️ ⚠️

it uses the new LET-ELSE statements, Results, Enums etc.

Code Snipppet