Skip to content

Instantly share code, notes, and snippets.

@samuelhnrq
Created December 10, 2017 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save samuelhnrq/9ddcd3e4ccb13b90cd257fa9c88dd9ec to your computer and use it in GitHub Desktop.
Save samuelhnrq/9ddcd3e4ccb13b90cd257fa9c88dd9ec 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