diff --git a/2025/11/p1.rs b/2025/11/p1.rs new file mode 100644 index 0000000..aa3fc20 --- /dev/null +++ b/2025/11/p1.rs @@ -0,0 +1,37 @@ +#![feature(slice_split_once)] + +use std::collections::HashMap; + +#[unsafe(no_mangle)] +pub unsafe extern "Rust" fn challenge_usize(buf: &[u8]) -> usize { + let conns = buf[..(buf.len() - 1)] + .split(|&b| b == b'\n') + .map(|ln| { + let (left, right) = ln.split_once(|&b| b == b':').unwrap(); + let conns = unsafe { str::from_utf8_unchecked(right) } + .trim() + .split(' ') + .collect::>(); + + (unsafe { str::from_utf8_unchecked(left) }, conns) + }) + .collect::>(); + + println!("{conns:#?}"); + + count_paths(&conns, "you") +} + +fn count_paths(set: &HashMap<&str, Vec<&str>>, from: &str) -> usize { + let mut count = 0; + + for &subk in set.get(from).unwrap() { + if subk == "out" { + count += 1; + } else { + count += count_paths(set, subk); + } + } + + count +}