From d3ce12693bc84006160c007d9c75da729e49e49b Mon Sep 17 00:00:00 2001 From: Keenan Tims Date: Sun, 22 Dec 2024 21:48:52 -0800 Subject: [PATCH] day23: part 1 solution --- .aoc_tiles/tiles/2024/23.png | Bin 4280 -> 7699 bytes README.md | 5 +- src/day23.rs | 144 +++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + 4 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 src/day23.rs diff --git a/.aoc_tiles/tiles/2024/23.png b/.aoc_tiles/tiles/2024/23.png index 269ba34872278b644c0e550c69a04a7d5e159ea5..e8f4326276a6522e4fcfae3b3d8fb2686bab706d 100644 GIT binary patch literal 7699 zcmX9@1ymI8*B+1t357)g>0V$#x?4&>LAsHW4vD2Z1teX%M7miJSU{FWxyZc$)%9}Z95aaAIrLwZp(_hP} zw6x6s(yn;zS9@S1_X`4J$(Vc_$>S%3zt8aZJGFlkQ65Jd?H(*y`_0^FZbAXLq;Pv%CvcR}<@gK>(is-<5v{N?@tWo1rOCSt{(&8!BIi=*lG z3J4q`$B4~jk9&o8j$!4Vw0DIG{0e*tSrK;VxmtTdgWo+4>vkg9oXY%TIn@9F`I^R- z_>5lW6H|PCT4-5fCw6J*sBH%2XJy#Bf<^t6KIEH9B^v9^x*>9P4hmHUFsuGH%7k>7 za{P{h@zDeyLA-Gpu+!7`iIv_RWb)g82xU17p~rq}vZN2|4o$&DN2F%uuijsyw8vm` zazpCxC6>VTg>qF}*Z8DXND&#V(?k#5?1%@#SEE+dIk&@lMtSX292@?;wMJ6%+7)uU z5(^g=7u$3MV{RmG{{B|<{d-qe7b!XU@p8K)FK?1YB&FGEIjqx>cSk6|gPSUk6ky#e zu?#Im`FbaS(Vx^qj60f>#0wcE*OLF`C{VxHPm3SJpbY@&l|O{bw^mNih3V7Oy*gRM zeg_LDcTH#Fb8y9HB8g(iS>mQswntT*2k_l)oA=hHTLJ(;LM$B@7~Q|zAfOaJq~K_d)qCd^>Tm41mQ*Uw{8Z5tKsv3 z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5$tf&!~O%;I-+jEV^J=TD&i+u$jvAgT|kFpR8l7bdF@l2#PB^lBYOp*EE z^PL;00^MmP%&Wj*3$7`7qMoe8%;>dgR6$*%v1eh@csQih<^E(s)+cCi#B=dFS(%Rx zpD)=+z3pdF5LKo@SwadVd|7pd#x1`zBa@M&I=m(7hV4z8muDrBz8-78y~NlMX2plt z#g*S)+H87e#dZ%(Ia|N}|6=Sa)r9YFDZ4!In#v<@BR=4Y!aA#=|93mTwg1^R(+DO$ zkW72K6I{VSkPsjEN)y`-uDHM^{%BJD)%R1f&R|YrJRxN{3B@ODVPRIBi){gOmD!S0 emcNYtqgxYumb?F82oAnTKn!o1!HabrBL54ud0Gbm diff --git a/README.md b/README.md index 422c0bf..f23874d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

- 2024 - 43 ⭐ - Rust + 2024 - 44 ⭐ - Rust

@@ -68,4 +68,7 @@ + + + diff --git a/src/day23.rs b/src/day23.rs new file mode 100644 index 0000000..6dbbbdf --- /dev/null +++ b/src/day23.rs @@ -0,0 +1,144 @@ +use std::fmt::Debug; + +use aoc_runner_derive::aoc; +use itertools::Itertools; +use rustc_hash::{FxHashMap, FxHashSet}; + +#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] +struct Node([char; 2]); + +impl Debug for Node { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{}", self.0.iter().join(""))) + } +} + +impl From<[char; 2]> for Node { + fn from(value: [char; 2]) -> Self { + Node(value) + } +} + +impl TryFrom> for Node { + type Error = <[char; 2] as TryFrom>>::Error; + fn try_from(value: Vec) -> Result { + let array: [char; 2] = value.try_into()?; + Ok(Self(array)) + } +} + +struct Network { + nodes: Vec, + edges: FxHashMap>, +} + +impl Network { + fn groups_3(&self) -> FxHashSet> { + let mut sets = FxHashSet::default(); + for n in &self.nodes { + let neighbours = self.edges.get(n).unwrap(); + for neigh in neighbours { + let neighbours2 = self.edges.get(neigh).unwrap(); + for neigh2 in neighbours2 { + let neighbours3 = self.edges.get(neigh2).unwrap(); + if neighbours3.contains(n) { + let mut set = vec![*n, *neigh, *neigh2]; + set.sort(); + sets.insert(set); + } + } + } + } + sets + } +} + +impl From<&str> for Network { + fn from(input: &str) -> Self { + let mut nodes = Vec::new(); + let mut edges = FxHashMap::default(); + for line in input.lines() { + let (node1, node2) = line.split_once('-').unwrap(); + let (node1, node2): (Node, Node) = ( + node1.chars().collect_vec().try_into().unwrap(), + node2.chars().collect_vec().try_into().unwrap(), + ); + if !nodes.contains(&node1) { + nodes.push(node1); + } + if !nodes.contains(&node2) { + nodes.push(node2); + } + edges.entry(node1).or_insert(Vec::new()).push(node2); + edges.entry(node2).or_insert(Vec::new()).push(node1); + } + Self { nodes, edges } + } +} + +fn parse(input: &str) -> Network { + input.into() +} + +#[aoc(day23, part1)] +pub fn part1(input: &str) -> i64 { + let network = parse(input); + println!("edges: {:?}", network.edges); + let sets = network.groups_3(); + let t_count = sets.iter().filter(|set| set.iter().any(|s| s.0[0] == 't')).count(); + println!("groups: {:?}", sets); + + t_count as i64 +} + +#[aoc(day23, part2)] +pub fn part2(input: &str) -> String { + todo!() +} + +#[cfg(test)] +mod tests { + use super::*; + const EXAMPLE: &str = "kh-tc +qp-kh +de-cg +ka-co +yn-aq +qp-ub +cg-tb +vc-aq +tb-ka +wh-tc +yn-cg +kh-ub +ta-co +de-co +tc-td +tb-wq +wh-td +ta-ka +td-qp +aq-cg +wq-ub +ub-vc +de-ta +wq-aq +wq-vc +wh-yn +ka-de +kh-ta +co-tc +wh-qp +tb-vc +td-yn"; + + #[test] + fn part1_example() { + assert_eq!(part1(EXAMPLE), 7); + } + + #[test] + fn part2_example() { + assert_eq!(part2(EXAMPLE), "co,de,ka,ta"); + } +} diff --git a/src/lib.rs b/src/lib.rs index 320bb98..6adecb4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,7 @@ pub mod day2; pub mod day20; pub mod day21; pub mod day22; +pub mod day23; pub mod day3; pub mod day4; pub mod day5;