take times

This commit is contained in:
Johannes Schaefer
2018-12-05 15:15:18 +01:00
parent 50cd1d6b00
commit 32843531f8
5 changed files with 26 additions and 9 deletions

View File

@@ -1,15 +1,19 @@
use std::time::Instant;
use utils;
pub fn task1() {
let mut input = utils::read_file("input/day05.txt");
let start = Instant::now();
input = reduce(input.as_str());
println!("resulting polymer: {}", input);
println!("Duration: {:?}", Instant::now() - start);
println!("RESULT: {}", input.len());
}
pub fn task2() {
let input = utils::read_file("input/day05.txt");
let start = Instant::now();
let input = reduce(&input);
let best = "abcdefghijklmnopqrstuvwxyz"
.chars()
.map(|c| {
@@ -25,6 +29,7 @@ pub fn task2() {
}).min_by_key(|it| it.1)
.unwrap();
println!("Duration: {:?}", Instant::now() - start);
println!("Best: {} (length {})", best.0, best.1);
}
@@ -42,13 +47,7 @@ fn reduce(input: &str) -> String {
}
if let Some(last) = last {
if c.is_lowercase()
&& last.is_uppercase()
&& c == last.to_lowercase().next().unwrap()
|| last.is_lowercase()
&& c.is_uppercase()
&& last == c.to_lowercase().next().unwrap()
{
if c.eq_ignore_ascii_case(&last) && c != last {
stack.pop();
} else {
stack.push(c);