From 56f2593cf101f1812547d121b6811fcdc69413c4 Mon Sep 17 00:00:00 2001 From: nekineki Date: Thu, 26 Dec 2024 20:58:23 +0100 Subject: day23 part1 --- 2024/day23.rs | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 2024/day23.rs (limited to '2024/day23.rs') 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 = 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> = 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, ); +} -- cgit v1.2.3