From dba149888be658eba717ef4f71b750c4e4e00b59 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sun, 11 Dec 2016 21:43:01 -0500 Subject: [PATCH] [2016][rust][10.0] start parsing bots --- 2016/rust/src/day_10.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 2016/rust/src/lib.rs | 1 + 2016/rust/src/main.rs | 2 +- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 2016/rust/src/day_10.rs diff --git a/2016/rust/src/day_10.rs b/2016/rust/src/day_10.rs new file mode 100644 index 0000000..e1a30c9 --- /dev/null +++ b/2016/rust/src/day_10.rs @@ -0,0 +1,40 @@ +use regex::Regex; + +use errors::*; + +pub fn solve(input: &str) -> Result { + Ok("".into()) +} + +struct Factory { + bots: Vec, +} + +impl Factory { + fn parse(input: &str) -> Result { + let re = Regex::new(r"bot (\d+) gives low to (bot|output) (\d+) and high to (bot|output) (\d+)").unwrap(); + + let mut bots = Vec::new(); + for line in input.lines() { + if let Some(caps) = re.captures(line) { + bots.push(0); + } + } + Ok(Factory { bots: bots }) + } +} + +#[test] +fn test_factory() { + let input = "value 5 goes to bot 2 +bot 2 gives low to bot 1 and high to bot 0 +value 3 goes to bot 1 +bot 1 gives low to output 1 and high to bot 0 +bot 0 gives low to output 2 and high to output 0 +value 2 goes to bot 2"; + let factory = Factory::parse(input).unwrap(); + + assert_eq!(factory.bots.len(), 3); + + // After running, outputs are 5, 2, 3. +} diff --git a/2016/rust/src/lib.rs b/2016/rust/src/lib.rs index 3ff0012..9da1125 100644 --- a/2016/rust/src/lib.rs +++ b/2016/rust/src/lib.rs @@ -15,3 +15,4 @@ pub mod day_05; pub mod day_06; pub mod day_07; pub mod day_08; +pub mod day_10; diff --git a/2016/rust/src/main.rs b/2016/rust/src/main.rs index d984eee..4fe02bc 100644 --- a/2016/rust/src/main.rs +++ b/2016/rust/src/main.rs @@ -10,7 +10,7 @@ fn main() { let mut input = String::new(); io::stdin().read_to_string(&mut input).ok(); - let solution = day_08::solve(&input)?; + let solution = day_10::solve(&input)?; println!("{}", solution); Ok(())