From 3206258ce33a749d16eec7770a8f71f814405780 Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Fri, 30 Dec 2022 22:11:16 +0100 Subject: [PATCH] Try fixing day16 --- Cargo.lock | 231 +--------------------------------------------- day16/Cargo.toml | 3 +- day16/src/main.rs | 33 ++++--- 3 files changed, 24 insertions(+), 243 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aaf5bd7..e7050d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,23 +28,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dbdbb2877d26e0647c6b8125802b2ecf2dc2a28d864dde41e6f9b9a54da08fe" -[[package]] -name = "async-trait" -version = "0.1.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d1d8ab452a3936018a687b20e6f7cf5363d713b732b8884001317b0e48aa3" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "async_once" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ce4f10ea3abcd6617873bae9f91d1c5332b4a778bd9ce34d0cd517474c1de82" - [[package]] name = "autocfg" version = "1.1.0" @@ -90,43 +73,6 @@ version = "1.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aaa3a8d9a1ca92e282c96a32d6511b695d7d994d1d102ba85d279f9b2756947f" -[[package]] -name = "cached" -version = "0.40.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b4147cd94d5fbdc2ab71b11d50a2f45493625576b3bb70257f59eedea69f3d" -dependencies = [ - "async-trait", - "async_once", - "cached_proc_macro", - "cached_proc_macro_types", - "futures", - "hashbrown 0.12.3", - "instant", - "lazy_static", - "once_cell", - "thiserror", - "tokio", -] - -[[package]] -name = "cached_proc_macro" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "751f7f4e7a091545e7f6c65bacc404eaee7e87bfb1f9ece234a1caa173dc16f2" -dependencies = [ - "cached_proc_macro_types", - "darling", - "quote", - "syn", -] - -[[package]] -name = "cached_proc_macro_types" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a4f925191b4367301851c6d99b09890311d74b0d43f274c0b34c86d308a3663" - [[package]] name = "cc" version = "1.0.78" @@ -226,41 +172,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "darling" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn", -] - -[[package]] -name = "darling_macro" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" -dependencies = [ - "darling_core", - "quote", - "syn", -] - [[package]] name = "day01" version = "0.1.0" @@ -362,7 +273,7 @@ name = "day14" version = "0.1.0" dependencies = [ "bitvec_simd", - "hashbrown 0.13.1", + "hashbrown", "termion", ] @@ -377,8 +288,7 @@ dependencies = [ name = "day16" version = "0.1.0" dependencies = [ - "bitvec_simd", - "cached", + "bitvec", "regex", ] @@ -471,67 +381,6 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" -[[package]] -name = "futures" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" - -[[package]] -name = "futures-io" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" - -[[package]] -name = "futures-sink" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" - -[[package]] -name = "futures-task" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" - -[[package]] -name = "futures-util" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" -dependencies = [ - "futures-core", - "futures-sink", - "futures-task", - "pin-project-lite", - "pin-utils", -] - [[package]] name = "getrandom" version = "0.2.8" @@ -543,12 +392,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "hashbrown" version = "0.13.1" @@ -573,21 +416,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - [[package]] name = "io-lifetimes" version = "1.0.3" @@ -723,18 +551,6 @@ version = "6.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" -[[package]] -name = "pin-project-lite" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -974,49 +790,6 @@ dependencies = [ "redox_termios", ] -[[package]] -name = "thiserror" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tokio" -version = "1.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" -dependencies = [ - "autocfg", - "pin-project-lite", - "tokio-macros", - "windows-sys", -] - -[[package]] -name = "tokio-macros" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "unicode-ident" version = "1.0.6" diff --git a/day16/Cargo.toml b/day16/Cargo.toml index 468ca5d..3fbbc27 100644 --- a/day16/Cargo.toml +++ b/day16/Cargo.toml @@ -8,6 +8,5 @@ build = true app = true [dependencies] -cached = "0.40.0" +bitvec = "1.0.1" regex = "1.7.0" -bitvec_simd = { git = "https://github.com/Imberflur/bitvec_simd", branch = "master" } diff --git a/day16/src/main.rs b/day16/src/main.rs index e5706ac..bdfc3df 100644 --- a/day16/src/main.rs +++ b/day16/src/main.rs @@ -5,10 +5,12 @@ use std::{ ops::Deref, }; -use bitvec_simd::BitVec; -use cached::proc_macro::cached; +use bitvec::vec::BitVec; use regex::Regex; +type Idx = usize; +type Distance = usize; + #[derive(Debug, Default, PartialEq, Eq)] enum SolvePuzzle { First, @@ -20,22 +22,30 @@ enum SolvePuzzle { struct Valve { name: String, flow: u32, - leads_to: Vec, + leads_to: Vec, } #[derive(Debug)] struct Valves { inner: Vec, + _next: HashMap<(Idx, Idx), (Idx, Distance)>, } impl Valves { pub fn start_idx(&self) -> usize { self.inner .iter() - .enumerate() - .find(|(_idx, valve)| valve.name == "AA") + .position(|valve| valve.name == "AA") .expect("Where to start now?") - .0 + } +} + +impl Valves { + fn indices_in_ideal_order(&self, opened: &BitVec, time_left: u32) -> Vec { + (0_usize..self.inner.len()) + .filter(|&idx| !opened[idx]) + .map(|idx| todo!()); + todo!() } } @@ -85,13 +95,12 @@ fn parse_input(reader: R) -> Valves { } }) .collect(); - Valves { inner } + Valves { + inner, + _next: HashMap::new(), + } } -#[cached( - key = "(usize, u32, Vec)", - convert = r#"{ (current_valve, time_left, opened.clone().into_usizes()) }"# -)] fn solve(valves: &Valves, current_valve: usize, time_left: u32, opened: &mut BitVec) -> u32 { if time_left == 0 { return 0; @@ -141,7 +150,7 @@ fn solve(valves: &Valves, current_valve: usize, time_left: u32, opened: &mut Bit fn solve_first_puzzle(reader: R) -> u32 { let valves = parse_input(reader); - let mut opened = BitVec::zeros(valves.len()); + let mut opened = BitVec::repeat(false, valves.len()); solve(&valves, valves.start_idx(), 30, &mut opened) }