From 9b287a0098eb9b456daa314a44f510320a6853a2 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Sun, 9 Dec 2018 13:02:54 +0100 Subject: [PATCH] Prepare future scaffolding. Also reformat the code, but that is nothing significant. --- 2018/src/day01.rs | 6 +++--- 2018/src/day02.rs | 3 +-- 2018/src/day03.rs | 3 +-- 2018/src/day04.rs | 16 ++++++++-------- 2018/src/day06.rs | 2 +- 2018/src/day10.rs | 25 +++++++++++++++++++++++++ 2018/src/day11.rs | 25 +++++++++++++++++++++++++ 2018/src/day12.rs | 25 +++++++++++++++++++++++++ 2018/src/day13.rs | 25 +++++++++++++++++++++++++ 2018/src/day14.rs | 25 +++++++++++++++++++++++++ 2018/src/day15.rs | 25 +++++++++++++++++++++++++ 2018/src/day16.rs | 25 +++++++++++++++++++++++++ 2018/src/day17.rs | 25 +++++++++++++++++++++++++ 2018/src/day18.rs | 25 +++++++++++++++++++++++++ 2018/src/day19.rs | 25 +++++++++++++++++++++++++ 2018/src/day20.rs | 25 +++++++++++++++++++++++++ 2018/src/day21.rs | 25 +++++++++++++++++++++++++ 2018/src/day22.rs | 25 +++++++++++++++++++++++++ 2018/src/day23.rs | 25 +++++++++++++++++++++++++ 2018/src/day24.rs | 25 +++++++++++++++++++++++++ 2018/src/day25.rs | 25 +++++++++++++++++++++++++ 2018/src/lib.rs | 40 +++++++++++++++++++++++++++++++++++++--- 2018/src/main.rs | 9 +++++---- 23 files changed, 456 insertions(+), 23 deletions(-) create mode 100644 2018/src/day10.rs create mode 100644 2018/src/day11.rs create mode 100644 2018/src/day12.rs create mode 100644 2018/src/day13.rs create mode 100644 2018/src/day14.rs create mode 100644 2018/src/day15.rs create mode 100644 2018/src/day16.rs create mode 100644 2018/src/day17.rs create mode 100644 2018/src/day18.rs create mode 100644 2018/src/day19.rs create mode 100644 2018/src/day20.rs create mode 100644 2018/src/day21.rs create mode 100644 2018/src/day22.rs create mode 100644 2018/src/day23.rs create mode 100644 2018/src/day24.rs create mode 100644 2018/src/day25.rs diff --git a/2018/src/day01.rs b/2018/src/day01.rs index c600644..20fc351 100644 --- a/2018/src/day01.rs +++ b/2018/src/day01.rs @@ -1,6 +1,7 @@ use std::collections::HashSet; use std::io; use std::io::prelude::*; + use common; pub struct Day01 {} @@ -46,9 +47,10 @@ impl common::Solution for Day01 { #[cfg(test)] mod tests { - use super::*; use common::Solution; + use super::*; + #[test] fn samples_part1() { let mut instance = Day01::new(); @@ -74,6 +76,4 @@ mod tests { assert_eq!("5", instance.part2(&mut sample3.as_bytes())); assert_eq!("14", instance.part2(&mut sample4.as_bytes())); } - - } diff --git a/2018/src/day02.rs b/2018/src/day02.rs index 7e852eb..1cea6a5 100644 --- a/2018/src/day02.rs +++ b/2018/src/day02.rs @@ -24,8 +24,7 @@ fn distance(a: &str, b: &str) -> usize { } #[derive(Default)] -pub struct Day02 { -} +pub struct Day02 {} impl Day02 { pub fn new() -> Day02 { diff --git a/2018/src/day03.rs b/2018/src/day03.rs index 4a9de32..35f68b8 100644 --- a/2018/src/day03.rs +++ b/2018/src/day03.rs @@ -17,7 +17,6 @@ struct Claim { } impl Claim { - fn xrange(&self) -> Range { self.x..(self.x + self.width) } @@ -52,7 +51,7 @@ impl Day03 { let line = line.unwrap(); let matched = matcher.captures(&line).unwrap(); - let claim = Claim{ + let claim = Claim { x: matched[2].parse().unwrap(), y: matched[3].parse().unwrap(), width: matched[4].parse().unwrap(), diff --git a/2018/src/day04.rs b/2018/src/day04.rs index a9a3249..7316070 100644 --- a/2018/src/day04.rs +++ b/2018/src/day04.rs @@ -1,14 +1,14 @@ +use std::collections::HashMap; use std::io; use std::io::BufRead; use chrono::DateTime; use chrono::offset::TimeZone; use chrono::offset::Utc; +use chrono::Timelike; use regex::Regex; use common; -use std::collections::HashMap; -use chrono::Timelike; #[derive(Debug, PartialEq, PartialOrd, Ord, Eq, Copy, Clone)] enum EventType { @@ -37,7 +37,7 @@ impl Day04 { self.events.clear(); let reader = io::BufReader::new(input); - let scanner = Regex::new(r"^\[([^\]]+)\] (Guard #(\d+)|falls asleep|wakes up)").unwrap(); + let scanner = Regex::new(r"^\[([^]]+)] (Guard #(\d+)|falls asleep|wakes up)").unwrap(); for line in reader.lines() { let line = line.unwrap(); @@ -59,7 +59,7 @@ impl Day04 { self.events.sort_unstable(); } - fn get_sleeps(&self) -> HashMap { + fn get_sleeps(&self) -> HashMap { let mut sleeps = HashMap::new(); let mut guard: Option = None; let mut sleep_start: Option> = None; @@ -70,12 +70,12 @@ impl Day04 { EventType::SHIFT(val) => { guard = Some(*val); sleep_start = None; - }, + } EventType::SLEEP => { sleep_start = Some(event.time.clone()); - }, + } EventType::WAKE => { - let mut minutes = sleeps.entry(guard.unwrap()).or_insert([0u32;60]); + let mut minutes = sleeps.entry(guard.unwrap()).or_insert([0u32; 60]); for m in sleep_start.unwrap().minute()..event.time.minute() { minutes[m as usize] += 1; } @@ -86,7 +86,7 @@ impl Day04 { sleeps } - fn format_results(sleepers: HashMap, scores: HashMap) -> String { + fn format_results(sleepers: HashMap, scores: HashMap) -> String { let (best_sleeper, _) = scores.iter().max_by(|&(_, a), &(_, b)| a.cmp(b)).unwrap(); let best_minute = sleepers[best_sleeper].iter().enumerate() diff --git a/2018/src/day06.rs b/2018/src/day06.rs index 8cda239..dba20f4 100644 --- a/2018/src/day06.rs +++ b/2018/src/day06.rs @@ -3,8 +3,8 @@ use std::io::BufRead; use std::io::BufReader; use std::io::Read; -use common::Solution; use common::GroupingCount; +use common::Solution; #[derive(Copy, Clone, Debug)] struct Coordinate { diff --git a/2018/src/day10.rs b/2018/src/day10.rs new file mode 100644 index 0000000..6511175 --- /dev/null +++ b/2018/src/day10.rs @@ -0,0 +1,25 @@ +use std::io::Read; + +use common::Solution; + +#[derive(Default)] +pub struct Day10 {} + +impl Day10 { + pub fn new() -> Self { + Default::default() + } +} + +impl Solution for Day10 { + fn part1(&mut self, _input: &mut Read) -> String { + unimplemented!() + } + + fn part2(&mut self, _input: &mut Read) -> String { + unimplemented!() + } +} + +#[cfg(test)] +mod tests {} diff --git a/2018/src/day11.rs b/2018/src/day11.rs new file mode 100644 index 0000000..bc80607 --- /dev/null +++ b/2018/src/day11.rs @@ -0,0 +1,25 @@ +use std::io::Read; + +use common::Solution; + +#[derive(Default)] +pub struct Day11 {} + +impl Day11 { + pub fn new() -> Self { + Default::default() + } +} + +impl Solution for Day11 { + fn part1(&mut self, _input: &mut Read) -> String { + unimplemented!() + } + + fn part2(&mut self, _input: &mut Read) -> String { + unimplemented!() + } +} + +#[cfg(test)] +mod tests {} diff --git a/2018/src/day12.rs b/2018/src/day12.rs new file mode 100644 index 0000000..e639797 --- /dev/null +++ b/2018/src/day12.rs @@ -0,0 +1,25 @@ +use std::io::Read; + +use common::Solution; + +#[derive(Default)] +pub struct Day12 {} + +impl Day12 { + pub fn new() -> Self { + Default::default() + } +} + +impl Solution for Day12 { + fn part1(&mut self, _input: &mut Read) -> String { + unimplemented!() + } + + fn part2(&mut self, _input: &mut Read) -> String { + unimplemented!() + } +} + +#[cfg(test)] +mod tests {} diff --git a/2018/src/day13.rs b/2018/src/day13.rs new file mode 100644 index 0000000..a97e80b --- /dev/null +++ b/2018/src/day13.rs @@ -0,0 +1,25 @@ +use std::io::Read; + +use common::Solution; + +#[derive(Default)] +pub struct Day13 {} + +impl Day13 { + pub fn new() -> Self { + Default::default() + } +} + +impl Solution for Day13 { + fn part1(&mut self, _input: &mut Read) -> String { + unimplemented!() + } + + fn part2(&mut self, _input: &mut Read) -> String { + unimplemented!() + } +} + +#[cfg(test)] +mod tests {} diff --git a/2018/src/day14.rs b/2018/src/day14.rs new file mode 100644 index 0000000..c2d5391 --- /dev/null +++ b/2018/src/day14.rs @@ -0,0 +1,25 @@ +use std::io::Read; + +use common::Solution; + +#[derive(Default)] +pub struct Day14 {} + +impl Day14 { + pub fn new() -> Self { + Default::default() + } +} + +impl Solution for Day14 { + fn part1(&mut self, _input: &mut Read) -> String { + unimplemented!() + } + + fn part2(&mut self, _input: &mut Read) -> String { + unimplemented!() + } +} + +#[cfg(test)] +mod tests {} diff --git a/2018/src/day15.rs b/2018/src/day15.rs new file mode 100644 index 0000000..eb71b83 --- /dev/null +++ b/2018/src/day15.rs @@ -0,0 +1,25 @@ +use std::io::Read; + +use common::Solution; + +#[derive(Default)] +pub struct Day15 {} + +impl Day15 { + pub fn new() -> Self { + Default::default() + } +} + +impl Solution for Day15 { + fn part1(&mut self, _input: &mut Read) -> String { + unimplemented!() + } + + fn part2(&mut self, _input: &mut Read) -> String { + unimplemented!() + } +} + +#[cfg(test)] +mod tests {} diff --git a/2018/src/day16.rs b/2018/src/day16.rs new file mode 100644 index 0000000..6617825 --- /dev/null +++ b/2018/src/day16.rs @@ -0,0 +1,25 @@ +use std::io::Read; + +use common::Solution; + +#[derive(Default)] +pub struct Day16 {} + +impl Day16 { + pub fn new() -> Self { + Default::default() + } +} + +impl Solution for Day16 { + fn part1(&mut self, _input: &mut Read) -> String { + unimplemented!() + } + + fn part2(&mut self, _input: &mut Read) -> String { + unimplemented!() + } +} + +#[cfg(test)] +mod tests {} diff --git a/2018/src/day17.rs b/2018/src/day17.rs new file mode 100644 index 0000000..e876bd8 --- /dev/null +++ b/2018/src/day17.rs @@ -0,0 +1,25 @@ +use std::io::Read; + +use common::Solution; + +#[derive(Default)] +pub struct Day17 {} + +impl Day17 { + pub fn new() -> Self { + Default::default() + } +} + +impl Solution for Day17 { + fn part1(&mut self, _input: &mut Read) -> String { + unimplemented!() + } + + fn part2(&mut self, _input: &mut Read) -> String { + unimplemented!() + } +} + +#[cfg(test)] +mod tests {} diff --git a/2018/src/day18.rs b/2018/src/day18.rs new file mode 100644 index 0000000..aef91b5 --- /dev/null +++ b/2018/src/day18.rs @@ -0,0 +1,25 @@ +use std::io::Read; + +use common::Solution; + +#[derive(Default)] +pub struct Day18 {} + +impl Day18 { + pub fn new() -> Self { + Default::default() + } +} + +impl Solution for Day18 { + fn part1(&mut self, _input: &mut Read) -> String { + unimplemented!() + } + + fn part2(&mut self, _input: &mut Read) -> String { + unimplemented!() + } +} + +#[cfg(test)] +mod tests {} diff --git a/2018/src/day19.rs b/2018/src/day19.rs new file mode 100644 index 0000000..e8ea334 --- /dev/null +++ b/2018/src/day19.rs @@ -0,0 +1,25 @@ +use std::io::Read; + +use common::Solution; + +#[derive(Default)] +pub struct Day19 {} + +impl Day19 { + pub fn new() -> Self { + Default::default() + } +} + +impl Solution for Day19 { + fn part1(&mut self, _input: &mut Read) -> String { + unimplemented!() + } + + fn part2(&mut self, _input: &mut Read) -> String { + unimplemented!() + } +} + +#[cfg(test)] +mod tests {} diff --git a/2018/src/day20.rs b/2018/src/day20.rs new file mode 100644 index 0000000..3fbf028 --- /dev/null +++ b/2018/src/day20.rs @@ -0,0 +1,25 @@ +use std::io::Read; + +use common::Solution; + +#[derive(Default)] +pub struct Day20 {} + +impl Day20 { + pub fn new() -> Self { + Default::default() + } +} + +impl Solution for Day20 { + fn part1(&mut self, _input: &mut Read) -> String { + unimplemented!() + } + + fn part2(&mut self, _input: &mut Read) -> String { + unimplemented!() + } +} + +#[cfg(test)] +mod tests {} diff --git a/2018/src/day21.rs b/2018/src/day21.rs new file mode 100644 index 0000000..401cd91 --- /dev/null +++ b/2018/src/day21.rs @@ -0,0 +1,25 @@ +use std::io::Read; + +use common::Solution; + +#[derive(Default)] +pub struct Day21 {} + +impl Day21 { + pub fn new() -> Self { + Default::default() + } +} + +impl Solution for Day21 { + fn part1(&mut self, _input: &mut Read) -> String { + unimplemented!() + } + + fn part2(&mut self, _input: &mut Read) -> String { + unimplemented!() + } +} + +#[cfg(test)] +mod tests {} diff --git a/2018/src/day22.rs b/2018/src/day22.rs new file mode 100644 index 0000000..f2fa66d --- /dev/null +++ b/2018/src/day22.rs @@ -0,0 +1,25 @@ +use std::io::Read; + +use common::Solution; + +#[derive(Default)] +pub struct Day22 {} + +impl Day22 { + pub fn new() -> Self { + Default::default() + } +} + +impl Solution for Day22 { + fn part1(&mut self, _input: &mut Read) -> String { + unimplemented!() + } + + fn part2(&mut self, _input: &mut Read) -> String { + unimplemented!() + } +} + +#[cfg(test)] +mod tests {} diff --git a/2018/src/day23.rs b/2018/src/day23.rs new file mode 100644 index 0000000..7f9e206 --- /dev/null +++ b/2018/src/day23.rs @@ -0,0 +1,25 @@ +use std::io::Read; + +use common::Solution; + +#[derive(Default)] +pub struct Day23 {} + +impl Day23 { + pub fn new() -> Self { + Default::default() + } +} + +impl Solution for Day23 { + fn part1(&mut self, _input: &mut Read) -> String { + unimplemented!() + } + + fn part2(&mut self, _input: &mut Read) -> String { + unimplemented!() + } +} + +#[cfg(test)] +mod tests {} diff --git a/2018/src/day24.rs b/2018/src/day24.rs new file mode 100644 index 0000000..1411e52 --- /dev/null +++ b/2018/src/day24.rs @@ -0,0 +1,25 @@ +use std::io::Read; + +use common::Solution; + +#[derive(Default)] +pub struct Day24 {} + +impl Day24 { + pub fn new() -> Self { + Default::default() + } +} + +impl Solution for Day24 { + fn part1(&mut self, _input: &mut Read) -> String { + unimplemented!() + } + + fn part2(&mut self, _input: &mut Read) -> String { + unimplemented!() + } +} + +#[cfg(test)] +mod tests {} diff --git a/2018/src/day25.rs b/2018/src/day25.rs new file mode 100644 index 0000000..ca9402e --- /dev/null +++ b/2018/src/day25.rs @@ -0,0 +1,25 @@ +use std::io::Read; + +use common::Solution; + +#[derive(Default)] +pub struct Day25 {} + +impl Day25 { + pub fn new() -> Self { + Default::default() + } +} + +impl Solution for Day25 { + fn part1(&mut self, _input: &mut Read) -> String { + unimplemented!() + } + + fn part2(&mut self, _input: &mut Read) -> String { + unimplemented!() + } +} + +#[cfg(test)] +mod tests {} diff --git a/2018/src/lib.rs b/2018/src/lib.rs index 99d6cfc..fcd6406 100644 --- a/2018/src/lib.rs +++ b/2018/src/lib.rs @@ -1,6 +1,8 @@ extern crate chrono; -#[macro_use] extern crate intrusive_collections; -#[macro_use] extern crate itertools; +#[macro_use] +extern crate intrusive_collections; +#[macro_use] +extern crate itertools; extern crate regex; pub mod common; @@ -13,6 +15,22 @@ pub mod day06; pub mod day07; pub mod day08; pub mod day09; +pub mod day10; +pub mod day11; +pub mod day12; +pub mod day13; +pub mod day14; +pub mod day15; +pub mod day16; +pub mod day17; +pub mod day18; +pub mod day19; +pub mod day20; +pub mod day21; +pub mod day22; +pub mod day23; +pub mod day24; +pub mod day25; pub fn get_impl(day: u32) -> Box { match day { @@ -25,6 +43,22 @@ pub fn get_impl(day: u32) -> Box { 7 => Box::new(day07::Day07::new()), 8 => Box::new(day08::Day08::new()), 9 => Box::new(day09::Day09::new()), + 10 => Box::new(day10::Day10::new()), + 11 => Box::new(day11::Day11::new()), + 12 => Box::new(day12::Day12::new()), + 13 => Box::new(day13::Day13::new()), + 14 => Box::new(day14::Day14::new()), + 15 => Box::new(day15::Day15::new()), + 16 => Box::new(day16::Day16::new()), + 17 => Box::new(day17::Day17::new()), + 18 => Box::new(day18::Day18::new()), + 19 => Box::new(day19::Day19::new()), + 20 => Box::new(day20::Day20::new()), + 21 => Box::new(day21::Day21::new()), + 22 => Box::new(day22::Day22::new()), + 23 => Box::new(day23::Day23::new()), + 24 => Box::new(day24::Day24::new()), + 25 => Box::new(day25::Day25::new()), val => panic!("Unimplemented day {}", val), } } @@ -36,7 +70,7 @@ mod tests { #[test] fn test_get_impl() { // Verify that we can load all days - let last_implemented = 8; + let last_implemented = 25; for d in 1..=last_implemented { get_impl(d); } diff --git a/2018/src/main.rs b/2018/src/main.rs index 63a1c43..14b9545 100644 --- a/2018/src/main.rs +++ b/2018/src/main.rs @@ -1,15 +1,16 @@ -extern crate chrono; -#[macro_use] extern crate clap; extern crate aoc_2018; +extern crate chrono; +#[macro_use] +extern crate clap; use std::fs; use std::io; use std::time::Instant; -use aoc_2018::get_impl; - use clap::Arg; +use aoc_2018::get_impl; + fn main() { let matches = app_from_crate!() .arg(Arg::with_name("day")