this post was submitted on 11 Dec 2025
16 points (100.0% liked)

Advent Of Code

1199 readers
1 users here now

An unofficial home for the advent of code community on programming.dev! Other challenges are also welcome!

Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

Everybody Codes is another collection of programming puzzles with seasonal events.

EC 2025

AoC 2025

Solution Threads

M T W T F S S
1 2 3 4 5 6 7
8 9 10 11 12

Visualisations Megathread

Rules/Guidelines

Relevant Communities

Relevant Links

Credits

Icon base by Lorc under CC BY 3.0 with modifications to add a gradient

console.log('Hello World')

founded 2 years ago
MODERATORS
 

Day 11: Reactor

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

you are viewing a single comment's thread
view the rest of the comments
[–] CameronDev@programming.dev 2 points 1 week ago (2 children)

Rust

After the struggles of yesterday, nice to have an easy one. Still havent solved yesterdays pt2, struggling to understand z3 + rust.

Hope everyone else isnt too demoralised by the last 2 days!

spoiler

   fn count_paths2(
        paths: &HashMap<&str, Vec<&str>>,
        seen: &mut HashMap<String, usize>,
        node: &str,
        dest: &str,
    ) -> usize {
        if let Some(c) = seen.get(node) {
            return *c;
        }
        if node == dest {
            seen.insert(node.to_string(), 1);
            return 1;
        }

        let Some(next) = paths.get(node) else {
            return 0;
        };
        let mut total_paths = 0;
        for node in next {
            total_paths += count_paths2(paths, seen, node, dest)
        }
        seen.insert(node.to_string(), total_paths);
        total_paths
    }

    #[test]
    fn test_y2025_day11_part2() {
        let input = include_str!("../../input/2025/day_11.txt");
        let mut paths: HashMap<&str, Vec<&str>> = HashMap::new();
        input.lines().for_each(|line| {
            let (source, dests) = line.split_once(":").unwrap();
            let dests = dests.split(" ").collect::<Vec<&str>>();
            paths.insert(source, dests);
        });

        // srv -> fft -> dac -> out

        let mut total1 = 1;
        {
            let mut seen = HashMap::new();
            total1 *= count_paths2(&paths, &mut seen, "svr", "fft");
        }
        {
            let mut seen = HashMap::new();
            total1 *= count_paths2(&paths, &mut seen, "fft", "dac");
        }
        {
            let mut seen = HashMap::new();
            total1 *= count_paths2(&paths, &mut seen, "dac", "out");
        }

        // srv -> dac -> fft -> out

        let mut total2 = 1;
        {
            let mut seen = HashMap::new();
            total2 *= count_paths2(&paths, &mut seen, "svr", "dac");
        }
        {
            let mut seen = HashMap::new();
            total2 *= count_paths2(&paths, &mut seen, "dac", "fft");
        }
        {
            let mut seen = HashMap::new();
            total2 *= count_paths2(&paths, &mut seen, "fft", "out");
        }

        println!("total: {}", total1 + total2);
        assert_eq!(total1 + total2, 509312913844956);
    }

[–] EnEnCode@programming.dev 2 points 1 week ago (1 children)

Good luck! If anything, yesterday's problem is motivating (if not challenging) because I'm trying to use it to learn the simplex algorithm (off mediocre online tutorials—doubly so considering I think the problem needs dual simplex [pun intended]). I've spent far more time with pencil and paper trying to understand the algorithm than actually try writing code for it.

[–] CameronDev@programming.dev 1 points 1 week ago* (last edited 1 week ago)

Yeah, ill have to bust out the pen and paper as well. Good learning excercise though :) Edit: If you find any good resources, please share :)