summaryrefslogtreecommitdiff
path: root/2025/11/rust/src
diff options
context:
space:
mode:
authormhsn <mail@mhsn.net>2026-03-18 21:48:13 +0000
committermhsn <mail@mhsn.net>2026-03-18 21:48:13 +0000
commit86bac31392a76da84817eec020d2b84d099b3cc1 (patch)
treee2ee52db59b86b914d5b4bcceb19c9b5d899fff4 /2025/11/rust/src
parent62fe361fc42dea75deaf7ac31c0ba6ba80e26a9c (diff)
downloadpuzzles-86bac31392a76da84817eec020d2b84d099b3cc1.tar.gz
puzzles-86bac31392a76da84817eec020d2b84d099b3cc1.zip
add other challenges supportHEADmaster
Diffstat (limited to '2025/11/rust/src')
-rw-r--r--2025/11/rust/src/main.rs84
1 files changed, 0 insertions, 84 deletions
diff --git a/2025/11/rust/src/main.rs b/2025/11/rust/src/main.rs
deleted file mode 100644
index 522d7ad..0000000
--- a/2025/11/rust/src/main.rs
+++ /dev/null
@@ -1,84 +0,0 @@
-use std::{cell::RefCell, collections::HashMap, io, rc::Rc};
-
-#[derive(PartialEq, Eq, Hash, Debug)]
-struct Node {
- device: String,
- dac: bool,
- fft: bool,
-}
-
-fn main() {
- let adj = io::stdin()
- .lines()
- .flatten()
- .map(|line| {
- let (k, v) = line.split_once(": ").unwrap();
- (
- String::from(k),
- String::from(v)
- .split_whitespace()
- .map(String::from)
- .collect(),
- )
- })
- .collect::<HashMap<String, Vec<String>>>();
-
- let cache = Rc::new(RefCell::new(HashMap::new()));
-
- let silver = paths_from(
- Node {
- device: String::from("you"),
- dac: true,
- fft: true,
- },
- &adj,
- Rc::clone(&cache),
- );
- let gold = paths_from(
- Node {
- device: String::from("svr"),
- dac: false,
- fft: false,
- },
- &adj,
- Rc::clone(&cache),
- );
-
- println!("silver: {silver}");
- println!("gold: {gold}");
-}
-
-fn paths_from(
- curr: Node,
- adj: &HashMap<String, Vec<String>>,
- cache: Rc<RefCell<HashMap<Node, usize>>>,
-) -> usize {
- if curr.device == "out" {
- if curr.dac && curr.fft {
- return 1;
- }
- return 0;
- }
-
- let Some(&v) = cache.borrow().get(&curr) else {
- let paths = adj
- .get(&curr.device)
- .unwrap()
- .iter()
- .map(|n| {
- paths_from(
- Node {
- device: n.clone(),
- dac: curr.dac || curr.device == "dac",
- fft: curr.fft || curr.device == "fft",
- },
- adj,
- Rc::clone(&cache),
- )
- })
- .sum();
- cache.borrow_mut().insert(curr, paths);
- return paths;
- };
- return v;
-}