Compare commits
2 Commits
50cd1d6b00
...
d10d36498c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d10d36498c | ||
|
|
32843531f8 |
16
Cargo.lock
generated
16
Cargo.lock
generated
@@ -11,6 +11,7 @@ name = "aoc_2018"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@@ -29,6 +30,19 @@ dependencies = [
|
||||
"time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.7.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.2.0"
|
||||
@@ -143,6 +157,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9a933f4e58658d7b12defcf96dc5c720f20832deebe3e0a19efd3b6aaeeb9e"
|
||||
"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
|
||||
"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878"
|
||||
"checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0"
|
||||
"checksum itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0d47946d458e94a1b7bcabbf6521ea7c037062c81f534615abcad76e84d4970d"
|
||||
"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"
|
||||
"checksum libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)" = "10923947f84a519a45c8fefb7dd1b3e8c08747993381adee176d7a82b4195311"
|
||||
"checksum memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a3eb002f0535929f1199681417029ebea04aadc0c7a4224b46be99c7f5d6a16"
|
||||
|
||||
@@ -6,3 +6,4 @@ authors = ["Johannes <jschaef@mail.uni-paderborn.de>"]
|
||||
[dependencies]
|
||||
regex = "1.1.0"
|
||||
chrono = "0.4.6"
|
||||
itertools = "0.7.11"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
extern crate chrono;
|
||||
extern crate itertools;
|
||||
extern crate regex;
|
||||
|
||||
pub mod tasks;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
fn main() {
|
||||
// aoc_2018::tasks::day05::task1();
|
||||
aoc_2018::tasks::day05::task1();
|
||||
aoc_2018::tasks::day05::task2();
|
||||
}
|
||||
|
||||
@@ -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| {
|
||||
@@ -18,13 +22,14 @@ pub fn task2() {
|
||||
reduce(
|
||||
&input
|
||||
.chars()
|
||||
.filter(|ch| ch.to_lowercase().next().unwrap() != c)
|
||||
.filter(|ch| ch.eq_ignore_ascii_case(&c))
|
||||
.collect::<String>(),
|
||||
).len(),
|
||||
)
|
||||
}).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);
|
||||
|
||||
Reference in New Issue
Block a user