diff --git a/2017/rust/src/day_04.rs b/2017/rust/src/day_04.rs
index 3033363..be85a75 100644
--- a/2017/rust/src/day_04.rs
+++ b/2017/rust/src/day_04.rs
@@ -1,6 +1,7 @@
use std::collections::HashSet;
use failure::Error;
+#[allow(dead_code)]
pub fn solve(input: &str) -> Result<String, Error> {
Ok(input
.trim()
@@ -11,11 +12,13 @@ pub fn solve(input: &str) -> Result<String, Error> {
.to_string())
}
+#[allow(dead_code)]
struct Passphrase {
words: String,
}
impl Passphrase {
+ #[allow(dead_code)]
fn is_valid(&self) -> bool {
let mut words = HashSet::new();
!self.words
diff --git a/2017/rust/src/day_05.rs b/2017/rust/src/day_05.rs
new file mode 100644
index 0000000..a972da3
--- /dev/null
+++ b/2017/rust/src/day_05.rs
@@ -0,0 +1,25 @@
+use std::collections::HashMap;
+use std::collections::hash_map::Entry;
+use failure::*;
+
+pub fn solve(input: &str) -> Result<String, Error> {
+ let mut jumps: HashMap<isize, isize> = input
+ .trim()
+ .lines()
+ .enumerate()
+ .map(|(i,x)| x.parse().map(|x| (i as isize, x)))
+ .collect::<Result<_,_>>()?;
+ let mut pc = 0;
+ let mut steps = 0;
+ while let Entry::Occupied(mut entry) = jumps.entry(pc) {
+ let offset = entry.get_mut();
+ pc += *offset;
+ if *offset >= 3 {
+ *offset -= 1;
+ } else {
+ *offset += 1;
+ }
+ steps += 1;
+ }
+ Ok(steps.to_string())
+}
diff --git a/2017/rust/src/main.rs b/2017/rust/src/main.rs
index a2983c8..bc88755 100644
--- a/2017/rust/src/main.rs
+++ b/2017/rust/src/main.rs
@@ -12,6 +12,7 @@ mod day_01;
mod day_02;
mod day_03;
mod day_04;
+mod day_05;
fn main() {
if let Err(e) = run() {
@@ -23,7 +24,7 @@ fn run() -> Result<(), Error> {
let mut input = String::new();
io::stdin().read_to_string(&mut input)?;
- let solution = day_04::solve(&input)?;
+ let solution = day_05::solve(&input)?;
println!("{}", solution);
Ok(())