diff options
| author | nekineki <nekineki@nekineki.net> | 2024-12-26 20:58:23 +0100 |
|---|---|---|
| committer | nekineki <nekineki@nekineki.net> | 2024-12-26 20:58:23 +0100 |
| commit | 56f2593cf101f1812547d121b6811fcdc69413c4 (patch) | |
| tree | 74b66d257d193390642a6857065180a499e400b9 /2024/day23.rs | |
| parent | 85920352be355ef7f987aba01d6ce3bfc6be5ff6 (diff) | |
day23 part1
Diffstat (limited to '2024/day23.rs')
| -rw-r--r-- | 2024/day23.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/2024/day23.rs b/2024/day23.rs new file mode 100644 index 0000000..65ed1a0 --- /dev/null +++ b/2024/day23.rs @@ -0,0 +1,57 @@ +#![allow(dead_code)] +#![allow(unused_variables)] +#![allow(unused_mut)] +use std::collections::HashMap; +use std::collections::HashSet; +use std::env; +use std::fs::File; +use std::io::Read; + +fn main() { + let args: Vec<String> = env::args().collect(); + let filename = if args.len() == 1 { + "in/".to_owned() + args[0].split('/').last().unwrap() + ".pzl" + } else { + args[1].clone() + }; + let mut f = File::open(filename).expect("cannot open file"); + let mut content = String::new(); + f.read_to_string(&mut content).expect("cannot read file"); + let lines = content.trim_end().split("\n"); + + let mut nodes: HashMap<&str, HashSet<&str>> = HashMap::new(); + let mut conns: HashSet<(&str, &str)> = HashSet::new(); + for line in lines { + let (a, b) = line.split_once("-").unwrap(); + nodes.entry(a).or_default().insert(b); + nodes.entry(b).or_default().insert(a); + conns.insert((a, b)); + } + println!("{:?}", nodes); + + let mut triplets: HashSet<Vec<&str>> = HashSet::new(); + for n0 in nodes.keys() { + if n0.starts_with("t") { + for n1 in &nodes[n0] { + for n2 in &nodes[n1] { + for n3 in &nodes[n2] { + if n0 == n3 { + let mut v = [*n0, *n1, *n2].to_vec(); + v.sort(); + println!("{:?}", v); + triplets.insert(v); + } + } + } + } + } + } + let res1 = triplets.len(); + + let mut res2 = 0; + + println!("res1: {}", res1); + println!("res2: {}", res2); + //assert_eq!(res1, ); + //assert_eq!(res2, ); +} |
