summary refs log tree commit diff homepage
path: root/src/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2016-12-18 14:53:10 -0500
committerJune McEnroe <june@causal.agency>2020-11-22 00:14:25 -0500
commit57e6b57aae9d26a84993706609fe6d64924842e4 (patch)
treed60beea10a7b46cd212773f23553e0f27b23b01a /src/bin
parentDay 17 (diff)
downloadaoc-57e6b57aae9d26a84993706609fe6d64924842e4.tar.gz
aoc-57e6b57aae9d26a84993706609fe6d64924842e4.zip
Day 17 part 2
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/day17.rs36
1 files changed, 31 insertions, 5 deletions
diff --git a/src/bin/day17.rs b/src/bin/day17.rs
index a80cbb8..c769f32 100644
--- a/src/bin/day17.rs
+++ b/src/bin/day17.rs
@@ -93,7 +93,7 @@ impl State {
     }
 }
 
-fn solve(passcode: &str) -> String {
+fn solve1(passcode: &str) -> String {
     let mut states = VecDeque::new();
     states.push_back(State::default());
 
@@ -107,16 +107,42 @@ fn solve(passcode: &str) -> String {
     panic!("no path to vault")
 }
 
+fn solve2(passcode: &str) -> usize {
+    let mut states = VecDeque::new();
+    states.push_back(State::default());
+
+    let mut longest = None;
+
+    while let Some(state) = states.pop_front() {
+        if state.is_vault() {
+            longest = Some(state.clone());
+        } else {
+            state.generate_states(&mut states, passcode);
+        }
+    }
+
+    longest.unwrap().path.len()
+}
+
 fn main() {
     let mut input = String::new();
     io::stdin().read_to_string(&mut input).unwrap();
 
-    println!("Part 1: {}", solve(input.trim()));
+    println!("Part 1: {}", solve1(input.trim()));
+    println!("Part 2: {}", solve2(input.trim()));
 }
 
 #[test]
 fn part1() {
-    assert_eq!("DDRRRD", solve("ihgpwlah"));
-    assert_eq!("DDUDRLRRUDRD", solve("kglvqrro"));
-    assert_eq!("DRURDRUDDLLDLUURRDULRLDUUDDDRR", solve("ulqzkmiv"));
+    assert_eq!("DDRRRD", solve1("ihgpwlah"));
+    assert_eq!("DDUDRLRRUDRD", solve1("kglvqrro"));
+    assert_eq!("DRURDRUDDLLDLUURRDULRLDUUDDDRR", solve1("ulqzkmiv"));
+}
+
+#[test]
+#[ignore]
+fn part2() {
+    assert_eq!(370, solve2("ihgpwlah"));
+    assert_eq!(492, solve2("kglvqrro"));
+    assert_eq!(830, solve2("ulqzkmiv"));
 }