-
-
Save chrisdone/2d72e1e7698b7df4e17ffd41805f88e9 to your computer and use it in GitHub Desktop.
My solution for the fifth day of advent of code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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