diff --git a/2018/07/Cargo.lock b/2018/07/Cargo.lock new file mode 100644 index 0000000..344c991 --- /dev/null +++ b/2018/07/Cargo.lock @@ -0,0 +1,95 @@ +[[package]] +name = "aho-corasick" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cfg-if" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "day-07" +version = "0.1.0" +dependencies = [ + "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "lazy_static" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libc" +version = "0.2.45" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "memchr" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex-syntax" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "thread_local" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ucd-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "utf8-ranges" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "version_check" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"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 lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" +"checksum libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "2d2857ec59fadc0773853c664d2d18e7198e83883e7060b63c924cb077bd5c74" +"checksum memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "db4c41318937f6e76648f42826b1d9ade5c09cafb5aef7e351240a70f39206e9" +"checksum regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37e7cbbd370869ce2e8dff25c7018702d10b21a20ef7135316f8daecd6c25b7f" +"checksum regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4e47a2ed29da7a9e1960e1639e7a982e6edc6d49be308a3b02daf511504a16d1" +"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" +"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" +"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" +"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" diff --git a/2018/07/Cargo.toml b/2018/07/Cargo.toml index 49b7d09..e90d11c 100644 --- a/2018/07/Cargo.toml +++ b/2018/07/Cargo.toml @@ -5,3 +5,4 @@ authors = ["Anders Olsson "] edition = "2018" [dependencies] +regex = "1.1" diff --git a/2018/07/example-01.txt b/2018/07/example-01.txt new file mode 100644 index 0000000..9ab25bf --- /dev/null +++ b/2018/07/example-01.txt @@ -0,0 +1,7 @@ +Step C must be finished before step A can begin. +Step C must be finished before step F can begin. +Step A must be finished before step B can begin. +Step A must be finished before step D can begin. +Step B must be finished before step E can begin. +Step D must be finished before step E can begin. +Step F must be finished before step E can begin. diff --git a/2018/07/input.txt b/2018/07/input.txt new file mode 100644 index 0000000..568ee75 --- /dev/null +++ b/2018/07/input.txt @@ -0,0 +1,101 @@ +Step D must be finished before step T can begin. +Step T must be finished before step K can begin. +Step O must be finished before step S can begin. +Step Y must be finished before step G can begin. +Step F must be finished before step Q can begin. +Step Q must be finished before step C can begin. +Step R must be finished before step X can begin. +Step E must be finished before step X can begin. +Step V must be finished before step U can begin. +Step U must be finished before step H can begin. +Step X must be finished before step S can begin. +Step L must be finished before step C can begin. +Step P must be finished before step B can begin. +Step A must be finished before step N can begin. +Step K must be finished before step W can begin. +Step H must be finished before step Z can begin. +Step W must be finished before step C can begin. +Step M must be finished before step J can begin. +Step S must be finished before step J can begin. +Step G must be finished before step I can begin. +Step Z must be finished before step I can begin. +Step C must be finished before step N can begin. +Step B must be finished before step J can begin. +Step J must be finished before step N can begin. +Step I must be finished before step N can begin. +Step O must be finished before step L can begin. +Step Z must be finished before step B can begin. +Step F must be finished before step Z can begin. +Step J must be finished before step I can begin. +Step Y must be finished before step R can begin. +Step Q must be finished before step N can begin. +Step U must be finished before step M can begin. +Step V must be finished before step C can begin. +Step W must be finished before step B can begin. +Step T must be finished before step E can begin. +Step Q must be finished before step W can begin. +Step A must be finished before step J can begin. +Step G must be finished before step Z can begin. +Step V must be finished before step B can begin. +Step E must be finished before step B can begin. +Step R must be finished before step J can begin. +Step W must be finished before step J can begin. +Step H must be finished before step N can begin. +Step G must be finished before step B can begin. +Step U must be finished before step X can begin. +Step Y must be finished before step M can begin. +Step B must be finished before step I can begin. +Step V must be finished before step I can begin. +Step S must be finished before step C can begin. +Step F must be finished before step K can begin. +Step X must be finished before step G can begin. +Step M must be finished before step C can begin. +Step U must be finished before step J can begin. +Step X must be finished before step H can begin. +Step L must be finished before step A can begin. +Step A must be finished before step K can begin. +Step V must be finished before step G can begin. +Step E must be finished before step U can begin. +Step P must be finished before step I can begin. +Step P must be finished before step G can begin. +Step A must be finished before step I can begin. +Step Y must be finished before step J can begin. +Step X must be finished before step K can begin. +Step B must be finished before step N can begin. +Step A must be finished before step M can begin. +Step E must be finished before step K can begin. +Step S must be finished before step N can begin. +Step Q must be finished before step A can begin. +Step L must be finished before step W can begin. +Step F must be finished before step A can begin. +Step K must be finished before step I can begin. +Step M must be finished before step N can begin. +Step O must be finished before step P can begin. +Step L must be finished before step J can begin. +Step Z must be finished before step N can begin. +Step Q must be finished before step U can begin. +Step V must be finished before step W can begin. +Step F must be finished before step P can begin. +Step F must be finished before step M can begin. +Step E must be finished before step Z can begin. +Step T must be finished before step L can begin. +Step F must be finished before step C can begin. +Step M must be finished before step G can begin. +Step Y must be finished before step S can begin. +Step C must be finished before step J can begin. +Step U must be finished before step I can begin. +Step Y must be finished before step W can begin. +Step Z must be finished before step C can begin. +Step Y must be finished before step N can begin. +Step Q must be finished before step P can begin. +Step P must be finished before step K can begin. +Step O must be finished before step M can begin. +Step W must be finished before step S can begin. +Step M must be finished before step B can begin. +Step X must be finished before step C can begin. +Step D must be finished before step C can begin. +Step H must be finished before step J can begin. +Step S must be finished before step G can begin. +Step C must be finished before step I can begin. +Step Y must be finished before step V can begin. +Step F must be finished before step I can begin. diff --git a/2018/07/src/main.rs b/2018/07/src/main.rs index e7a11a9..7bdd4ec 100644 --- a/2018/07/src/main.rs +++ b/2018/07/src/main.rs @@ -1,3 +1,40 @@ +use std::collections::HashMap; +use std::io::{self, BufRead}; + +use regex::Regex; + fn main() { - println!("Hello, world!"); + let re = Regex::new(r"Step ([A-Z]) must be finished before step ([A-Z]) can begin.") + .expect("failed to build regex"); + + let mut entries = io::stdin() + .lock() + .lines() + .filter_map(Result::ok) + .map(|line| { + let caps = re + .captures(&line) + .expect("failed to capture date"); + + let dependency = caps + .get(1) + .unwrap() + .as_str() + .chars() + .next() + .unwrap(); + + let step = caps + .get(2) + .unwrap() + .as_str() + .chars() + .next() + .unwrap(); + + (dependency, step) + }) + .collect::>(); + + println!("{:#?}", entries); }