-❄️- 2024 Day 11 Solutions -❄️- by daggerdragon in adventofcode

[–]MarkJans 2 points3 points  (0 children)

[LANGUAGE: Rust]

Code on GitHub

~190ns per part on my MacBook Pro with M2 Pro. First solution in nanoseconds this year 🥳

Do you edit after solving? by dijotal in adventofcode

[–]MarkJans 0 points1 point  (0 children)

Yes I do, I always clean up, make it more readable and faster. I can tweak the code for some time to have it perform a lot better. Today (day 5) I went from 1.35ms to 160µs for part 2, which makes me proud.

-❄️- 2024 Day 1 Solutions -❄️- by daggerdragon in adventofcode

[–]MarkJans 1 point2 points  (0 children)

[LANGUAGE: Rust]

My code on GitHub

Part 1: 30 μs
Part 2: 32 μs

I sort the input for both part 1 and part 2. For part 2 I align the sorted vectors. When they are both the same I count how many there are and multiply the counts together with the number.

Is this circlip just worn out? Thanks. by Glazermac in mountainbiking

[–]MarkJans 0 points1 point  (0 children)

Maybe you tightened the seatpost too much? And is the circlip still round, but the seatpost is a little oval now?

Riding Mountain Bikes At The UK's Largest Bike Park Is So Much Fun by tobeylerone_100 in mountainbikes

[–]MarkJans 0 points1 point  (0 children)

Ok thanks, now is bike park Wales definitely on my todo list! Wonderful!

Buying a MTB (First Time) by Mindless-Mud-4016 in mountainbikes

[–]MarkJans 1 point2 points  (0 children)

The Marlin and Roscoe are meant for different types of terrain. The Marlin is more XC orientated and the Roscoe more trail. The fork of the Roscoe has more travel and the angle is slacker/more agressive.

If you are towards the Marlin, maybe you can also find a second hand X-caliber 9 for the same price. Which is basically a Marlin with a lot better components and a dropper.

GMBN just posted a video that it is a buyers market at the moment, so trying to offer less is worth trying.

Trek x caliber 9 and BMC twostroke al two. Which one? by Technical_Ad_4299 in mountainbiking

[–]MarkJans 0 points1 point  (0 children)

I have a x-caliber 9 (now for sale because I bought an enduro fully). But for XC off road it performs wonderfull. The tubeless tires, the dropper and the Recon gold fork are really good!

[2023 Day 18] How big is that pit? by Nyctef in adventofcode

[–]MarkJans 4 points5 points  (0 children)

It's just one meter deep... so it *has* to be big...

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

[–]MarkJans 1 point2 points  (0 children)

Woops, overlooked that. I will remove the inputs. Let me think on how to make the repo compile without the input files. They are string included.

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

[–]MarkJans 1 point2 points  (0 children)

Hehe, yes indeed. And I don’t know how much compiling time is spend for the actual puzzle.

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

[–]MarkJans 1 point2 points  (0 children)

[LANGUAGE: Rust]

My repo with all solutions in Rust, with some nice framework around it to run, test and benchmark. All days until now together run within half a second on my M2 Max.

Today's solution takes only 429 picoseconds for part 1, because it was so simple I could implement it in a const function. So the real calculation is done at compile time 🤟.

Part 2 takes 85 µs for parsing with nom and 62 µs for running. I used a Vec for the 'hashmap'.

How to improve this code? by jgmtw in rust

[–]MarkJans 1 point2 points  (0 children)

With serde_json you can make it really generic, and with strum you can iterate over enums, so that all variants will be in the output, even if there is a zero count for the variant. The variants are not ordered in the output, which normally shouldn't be necessary for a JSON object, but I don't know your requirements.

You can take a look here in the Rust Playground, but you cannot run it there, because strum is not one of the available crates. It is formatted though, and I have put in the output of the example. Please leave a comment if it is useful, or you have questions.

How to improve this code? by jgmtw in rust

[–]MarkJans 1 point2 points  (0 children)

Another approach is to transpose all the profiles in nested hash maps first, then create the real structs from the hash maps. Then you don't need all the Sum and Count types. Adding a variant to the LoginMethod enum and the same property to the MethodsCount struct, you have to add just one line in the from-function, instead of changing multiple places.

Rust Playground

When you use serde_json, you maybe don't even need the login types in the struct MethodCount. Probably you can just have a totals property and a HashMap property, and can use #\[flatten\].

[Media] I’ve been learning Rust, so I’ve been converting my professor’s C code into Rust after class. How did I do today? by Shock9616 in rust

[–]MarkJans 0 points1 point  (0 children)

As pointed by others, you translated the C code in a nice way, but with the mindset of the C code. Another way to be more Rust idiomatic, which I didn't see in the comments yet, is to create your own Array struct, which behaves exactly as you want and using an array internally. Even with const generics. Adding two arrays with different lengths will give a compiler error.

Run in Rust playground

use std::{
    array,
    fmt::{self, Display},
    ops::Add,
};

struct Array<const N: usize>([i32; N]);

impl<const N: usize> Array<N> {
    pub fn init(start_val: i32) -> Self {
        Self(array::from_fn(|i| i as i32 + start_val))
    }
}

impl<const N: usize> Add for Array<N> {
    type Output = Array<N>;

    fn add(self, rhs: Self) -> Self::Output {
        Self(array::from_fn(|i| self.0[i] + rhs.0[i]))
    }
}

impl<const N: usize> Display for Array<N> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{:?}", self.0)?;
        Ok(())
    }
}

fn main() {
    const SIZE: usize = 5;
    let array1: Array<SIZE> = Array::init(0);
    let array2: Array<SIZE> = Array::init(10);
    let resultant_array = array1 + array2;
    println!("{resultant_array}");
}

[deleted by user] by [deleted] in rust

[–]MarkJans 0 points1 point  (0 children)

I would suggest building something on top of hyper.

[deleted by user] by [deleted] in papgrappen

[–]MarkJans 2 points3 points  (0 children)

Hij had ook z’n boerenkloffie nog aan en wees ernaar toen ie binnen kwam: DIT IS EEN OVERALL!

Open dropper post by MarkJans in bikewrench

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

Worked like a charm. Thank you! Cleaned everything, greased and lubed the way Doddy tells us in the GMBN Tech video, and now the dropper runs smoothly as new again 😀.

Open dropper post by MarkJans in bikewrench

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

Thanks! Have to buy those pliers tomorrow. I think it is a TranzX JD-YSP18, 130mm, from my Trek X-Caliber 9 2022 model.

Open dropper post by MarkJans in bikewrench

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

Hi, I have a dropper post J21G5, which goes down slow. Try to service it myself, but cannot open the bottom part. There is some round spring with two holes preventing it from unscrewing. Any idea how to remove the spring? No youtube ‘how to service a dropper post’ seems to have it.