Skip to content

Instantly share code, notes, and snippets.

@chrisdone
Forked from samuelhnrq/rust-day5.rs
Created December 10, 2017 22:46
Show Gist options
  • Save chrisdone/2d72e1e7698b7df4e17ffd41805f88e9 to your computer and use it in GitHub Desktop.
Save chrisdone/2d72e1e7698b7df4e17ffd41805f88e9 to your computer and use it in GitHub Desktop.
My solution for the fifth day of advent of code
extern crate time;
use std::fs::File;
use std::io::prelude::*;
fn main() {
let mut inpt = File::open("input/xmas5.txt").expect("file not found");
let mut content = String::new();
inpt.read_to_string(&mut content).unwrap();
let tm = time::now();
let mut kay: [i32; 1058] = [0; 1058]; //Hard coded this to see how fast it could become
for (x, line) in content.lines().enumerate() {
if line == "" {
continue;
}
kay[x] = line.parse().unwrap();
}
let mut counter = 0i64; //Kay is the array containing the maze
let mut ind = 0i32; //ind is current index
while ind < kay.len() as i32 {
counter += 1;
let i = ind as usize; //temporarary helper
let curr = kay[i];
if curr >= 3 {
kay[i] -= 1;
} else {
kay[i] += 1;
}
ind += curr;
}
let after = time::now() - tm;
println!(
"{}, is the answer, it took {}ms",
counter,
after.num_milliseconds()
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment