···11+use std::collections::HashMap;
22+13use advent_core::{day_stuff, ex_for_day, Day};
2435pub struct Day11;
4677+type Graph = HashMap<String, Vec<String>>;
88+type Seen = HashMap<(String, bool, bool), usize>;
99+1010+fn all_paths_to_out(node: &String, graph: &Graph, seen: &mut HashMap<String, usize>) -> usize {
1111+ if let Some(memo) = seen.get(node).copied() {
1212+ memo
1313+ } else if let Some(nexts) = graph.get(node) {
1414+ let mut amnt = 0;
1515+ for next in nexts.iter() {
1616+ if next == "out" {
1717+ amnt += 1;
1818+ } else {
1919+ amnt += all_paths_to_out(next, graph, seen);
2020+ }
2121+ }
2222+ seen.insert(node.clone(), amnt);
2323+ amnt
2424+ } else {
2525+ 0
2626+ }
2727+}
2828+2929+fn all_paths_to_out_with_constraints(
3030+ node: &String,
3131+ saw_dac: bool,
3232+ saw_fft: bool,
3333+ graph: &Graph,
3434+ seen: &mut Seen,
3535+) -> usize {
3636+ if let Some(memo) = seen.get(&(node.clone(), saw_dac, saw_fft)).copied() {
3737+ memo
3838+ } else if let Some(nexts) = graph.get(node) {
3939+ let mut amnt = 0;
4040+ for next in nexts.iter() {
4141+ if next == "out" && saw_fft && saw_dac {
4242+ amnt += 1;
4343+ } else {
4444+ let is_dac = next == "dac";
4545+ let is_fft = next == "fft";
4646+ amnt += all_paths_to_out_with_constraints(
4747+ next,
4848+ saw_dac || is_dac,
4949+ saw_fft || is_fft,
5050+ graph,
5151+ seen,
5252+ );
5353+ }
5454+ }
5555+ seen.insert((node.clone(), saw_dac, saw_fft), amnt);
5656+ amnt
5757+ } else {
5858+ 0
5959+ }
6060+}
6161+562impl Day for Day11 {
66- day_stuff!(11, "", "");
6363+ day_stuff!(11, "5", "2", Graph);
76488- fn part_1(_input: Self::Input) -> Option<String> {
99- None
6565+ fn part_1(input: Self::Input) -> Option<String> {
6666+ let mut seen = HashMap::with_capacity(input.len());
6767+ let start = "you".to_string();
6868+ let ans = all_paths_to_out(&start, &input, &mut seen);
6969+ Some(ans.to_string())
1070 }
11711212- fn part_2(_input: Self::Input) -> Option<String> {
1313- None
7272+ fn part_2(input: Self::Input) -> Option<String> {
7373+ let mut seen = HashMap::with_capacity(input.len());
7474+ let start = "svr".to_string();
7575+ let ans = all_paths_to_out_with_constraints(&start, false, false, &input, &mut seen);
7676+ Some(ans.to_string())
7777+ }
7878+7979+ fn parse_input(input: &str) -> Self::Input {
8080+ input
8181+ .lines()
8282+ .map(|l| {
8383+ let (k, v) = l.split_once(':').unwrap();
8484+ let v = v.trim().split(' ').map(str::to_string).collect::<Vec<_>>();
8585+ (k.to_string(), v)
8686+ })
8787+ .collect()
1488 }
1589}
+10
years/2025/src/examples/day_11/1.txt
···11+aaa: you hhh
22+you: bbb ccc
33+bbb: ddd eee
44+ccc: ddd eee fff
55+ddd: ggg
66+eee: out
77+fff: out
88+ggg: out
99+hhh: ccc fff iii
1010+iii: out