summary refs log tree commit diff homepage
path: root/2017/src/bin
diff options
context:
space:
mode:
authorJune McEnroe <programble@gmail.com>2017-12-05 00:22:25 -0500
committerJune McEnroe <programble@gmail.com>2017-12-05 00:22:25 -0500
commitd60c2ab2b2646b4459a71e23c7edb8ebf4877c91 (patch)
tree996be3f8d7f55d07f743a8d417e18bb93f6545c7 /2017/src/bin
parentDay 5 (diff)
downloadaoc-d60c2ab2b2646b4459a71e23c7edb8ebf4877c91.tar.gz
aoc-d60c2ab2b2646b4459a71e23c7edb8ebf4877c91.zip
Day 5, part 2
Diffstat (limited to '2017/src/bin')
-rw-r--r--2017/src/bin/day05.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/2017/src/bin/day05.rs b/2017/src/bin/day05.rs
index b8e21d9..e96138e 100644
--- a/2017/src/bin/day05.rs
+++ b/2017/src/bin/day05.rs
@@ -18,14 +18,42 @@ fn solve1(input: &str) -> u32 {
     unreachable!()
 }
 
+fn solve2(input: &str) -> u32 {
+    let mut jumps: Vec<isize> = input.lines()
+        .map(str::parse)
+        .map(Result::unwrap)
+        .collect();
+
+    let mut index = 0isize;
+    for step in 0.. {
+        if index < 0 || index >= jumps.len() as isize {
+            return step;
+        }
+        let jump = &mut jumps[index as usize];
+        index += *jump;
+        if *jump >= 3 {
+            *jump -= 1;
+        } else {
+            *jump += 1;
+        }
+    }
+    unreachable!()
+}
+
 fn main() {
     let mut input = String::new();
     io::stdin().read_to_string(&mut input).unwrap();
 
     println!("Part 1: {}", solve1(&input));
+    println!("Part 2: {}", solve2(&input));
 }
 
 #[test]
 fn part1() {
     assert_eq!(5, solve1("0\n3\n0\n1\n-3\n"));
 }
+
+#[test]
+fn part2() {
+    assert_eq!(10, solve2("0\n3\n0\n1\n-3\n"));
+}
r> 2024-09-25Add photos from September 15June McEnroe 2024-09-24Add photos from September 14June McEnroe 2024-09-24Add photos from September 12June McEnroe 2024-09-24Add photos from September 7June McEnroe 2024-09-24Allow not having descriptionsJune McEnroe I'm sorry, I can't keep writing descriptions. It makes posting photos take too long, I often don't know the words for what I'm looking at, and a good description is an entirely different work of art than the photo I took, and I'm just a photographer. It's visual art. 2024-09-23Automatically select the last used lens for a bodyJune McEnroe 2024-09-19Add photos from September 5June McEnroe Had to prefix the folder number onto these file names manually because they must have come out of a different scanner or something. 2024-09-15Add some more film stocks to the listJune McEnroe 2024-09-13Add photos from September 2June McEnroe 2024-09-13Add Fomapan 200 to films listJune McEnroe 2024-09-10Add August 29 picnic photosJune McEnroe 2024-09-08Apply some bold to trips renderingJune McEnroe This seems easier to visually scan. The only other thing I'd like is a nicer date rendering but JavaScript is useless for that. 2024-09-08Render trips hopefully more efficientlyJune McEnroe 2024-09-08Allow removing bodies and lensesJune McEnroe 2024-09-08Limit body width so it looks less silly on desktopJune McEnroe 2024-09-07Handle no film being loadedJune McEnroe 2024-09-07Fancy up the text a littleJune McEnroe