Skip Navigation
InitialsDiceBearhttps://github.com/dicebear/dicebearhttps://creativecommons.org/publicdomain/zero/1.0/„Initials” (https://github.com/dicebear/dicebear) by „DiceBear”, licensed under „CC0 1.0” (https://creativecommons.org/publicdomain/zero/1.0/)VI
vilcans @programming.dev
Posts 2
Comments 6
Day 8: Was I just lucky with the input data? (Rust solution)
  • Thanks for the answer! What you're saying seems to be true, but it wasn't given in the instructions, so I guess you were supposed to figure out that this was the case. It seems this was true for everyone, so it wasn't just me that got lucky. I got confused by my assertion failing on the example, because the second path reaches the goal in three steps which is not a multiple of the instruction length (2). This never happens with the real data. The example wraps around neatly at 6 instead, so just removing the assertion makes my code work on the example too.

  • Day 8: Was I just lucky with the input data? (Rust solution)

    I had 6 parallel paths, and for all of them, the goal node was found at the point where the directions string repeated. So I actually only had to search each of the paths for the point where I was on the goal position and the first direction. This worked on the input data, but not the example. See the assert in the code, and note that the statement println!("Found non-repeat at {node} step {step} (num dirs {num_directions})"); is never executed.

    At the end there's also the first attempt of brute-forcing the solution which seems like it would have taken nearly forever.

    ```rust use std::collections::HashMap;

    use regex::Regex;

    use crate::input::Source;

    pub fn execute(source: Source) -> impl std::fmt::Debug { let lines = source.lines(); let ([directions], [empty, nodes @ ..]) = lines.split_at(1) else { panic!("Wrong format"); }; assert!(empty.is_empty());

    let node_re = Regex::new(r"(...) = \((...), (...)\)").unwrap(); let nodes: HashMap = nodes .iter() .map(|line| { let caps = node_re.captures(line).unwrap(); let name = caps[1].to_string(); let left = caps[2].to_string(); let right = caps[3].to_string(); (name, (left, right)) }) .collect();

    let start_nodes: Vec = nodes.keys().filter(|n| n.ends_with('A')).cloned().collect(); let repeat_lengths: Vec = start_nodes .iter() .map(|node| { let (repeat_length, goal_steps) = find_repeats(node, directions, &nodes); assert!(goal_steps.is_empty()); // not a given, but that's what the input looks like dbg!(node, repeat_length, goal_steps); repeat_length }) .collect();

    repeat_lengths.iter().cloned().reduce(num::integer::lcm) }

    /// (repeat length, steps to goal node within repeat) fn find_repeats( starting_node: &str, directions: &str, nodes: &HashMap, ) -> (usize, Vec) { let mut node = starting_node.to_string(); let num_directions = directions.chars().count(); let mut goals = Vec::new(); for (step, dir) in directions.chars().cycle().enumerate() { if node.ends_with('Z') { if step % num_directions == 0 { println!("Found repeat at {node} step {step} (num dirs {num_directions})"); return (step, goals); } println!("Found non-repeat at {node} step {step} (num dirs {num_directions})"); goals.push(step); } let (left, right) = &nodes[&node]; node = match dir { 'L' => left.clone(), 'R' => right.clone(), other => panic!("Unknown dir {other}"), } } unreachable!() }

    // too slow #[allow(dead_code)] fn find_parallel( start_nodes: &[String], directions: &str, nodes: &HashMap, ) -> usize { let mut current_nodes = start_nodes.to_vec(); for (step, dir) in directions.chars().cycle().enumerate() { if current_nodes.iter().all(|n| n.ends_with('Z')) { return step; } for node in current_nodes.iter_mut() { let (left, right) = nodes[node].clone(); *node = match dir { 'L' => left, 'R' => right, other => panic!("Unknown dir {other}"), } } } unreachable!() } ```

    3
    Why do I feel that no matter how much I practice programming I will never be a programmer?
  • It sounds like you have the mindset that you have to learn programming before you start doing it. Which is especially hard today as there's so much information, so much to learn, so many tutorials to watch. There's always something to learn. Don't expect to reach a point when you "know" programming.

    Instead try this: Stop practicing and start programming. Start with a project that you want to do, for whatever reason. Some small utility, a really tiny game, a joke program, whatever that gets you to focus on creating something rather than learning something. You will learn the things you have to learn in order to progress on the project. This is completely normal, and a good skill to have, even for professional programmers.

  • Allowing to add functionalities in Rust
  • One way to implement Rust-based "plugins" is to turn the whole application/plugins relation on its head: Publish the main application as a crate, which lets the user build their own executable that uses the main application as a library. That way they can customize the app however they like, if the main app just has hooks for it.

  • Change password not working
  • Thanks, I hope 0.18 fixes it then. I tried logging in using another browser, and noticed that trying to log in gives the same infinite spinner. So it seems I can only use my account on the browser I'm on right now.

  • Change password not working

    I registered on the web site today and then tried to log in on Jerboa, but it gives the Incorrect Login message. I figured maybe my first (autogenerated) password was too long or had invalid characters in it. So I've tried several times to change it, but neither the Change Password box in Settings nor reset password works. Both of them just changes the button to a spinner whenever I click it. What's up?

    EDIT: It seems the same problem affects trying to log in (I'm still logged in on this browser, but I can't log in on any other). But it doesn't even seem to be specific to my user. No matter what username and password I give it, the button just keeps on spinning. Both on Firefox on Linux and Chrome on Android. So it should affect everyone. Strange.

    EDIT 2: Logging in doesn't work on other servers running 0.17.4 (tried https://discuss.tchncs.de/login and https://sh.itjust.works/login).

    3