summary refs log tree commit diff homepage
path: root/2017/src
diff options
context:
space:
mode:
Diffstat (limited to '2017/src')
-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"));
+}
who the fuck is scraeming "#define _GNU_SOURCE" at my house. show yourself, coward. i will never #define _GNU_SOURCE 2019-05-20Fix comparison warning in ttpreJune McEnroe 2019-05-20Add AuthorityJune McEnroe 2019-05-19Specify precedence of unary versions of operatorsJune McEnroe 2019-05-18Add compound assignment operators to orderJune McEnroe 2019-05-15Support simple assignment in orderJune McEnroe 2019-05-15Implement sizeof in orderJune McEnroe 2019-05-15Add orderJune McEnroe 2019-05-12Add T suffix in bitJune McEnroe 2019-05-10Highlight yacc and lex files as CJune McEnroe Their %-prefixed directives should probably be highlighted Macro. 2019-05-10Use val instead of suboptargJune McEnroe suboptarg doesn't exist in GNU. Hopefully BSD getsubopt also sets val on failure? 2019-05-09Add Parable of the SowerJune McEnroe 2019-05-07Add bit without buildJune McEnroe Need to do some stuff in the Makefile for lex and yacc and generating HTML pages for it. 2019-05-04Fix MANDIR typoJune McEnroe 2019-05-04Move relay to binJune McEnroe