Prepare future scaffolding.

Also reformat the code, but that is nothing significant.
This commit is contained in:
2018-12-09 13:02:54 +01:00
parent 9b04e3b2c9
commit 9b287a0098
23 changed files with 456 additions and 23 deletions

View File

@@ -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()));
}
}

View File

@@ -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 {

View File

@@ -17,7 +17,6 @@ struct Claim {
}
impl Claim {
fn xrange(&self) -> Range<usize> {
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(),

View File

@@ -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<usize, [u32;60]> {
fn get_sleeps(&self) -> HashMap<usize, [u32; 60]> {
let mut sleeps = HashMap::new();
let mut guard: Option<usize> = None;
let mut sleep_start: Option<DateTime<Utc>> = 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<usize, [u32;60]>, scores: HashMap<usize, u32>) -> String {
fn format_results(sleepers: HashMap<usize, [u32; 60]>, scores: HashMap<usize, u32>) -> String {
let (best_sleeper, _) = scores.iter().max_by(|&(_, a), &(_, b)| a.cmp(b)).unwrap();
let best_minute = sleepers[best_sleeper].iter().enumerate()

View File

@@ -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 {

25
2018/src/day10.rs Normal file
View File

@@ -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 {}

25
2018/src/day11.rs Normal file
View File

@@ -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 {}

25
2018/src/day12.rs Normal file
View File

@@ -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 {}

25
2018/src/day13.rs Normal file
View File

@@ -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 {}

25
2018/src/day14.rs Normal file
View File

@@ -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 {}

25
2018/src/day15.rs Normal file
View File

@@ -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 {}

25
2018/src/day16.rs Normal file
View File

@@ -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 {}

25
2018/src/day17.rs Normal file
View File

@@ -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 {}

25
2018/src/day18.rs Normal file
View File

@@ -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 {}

25
2018/src/day19.rs Normal file
View File

@@ -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 {}

25
2018/src/day20.rs Normal file
View File

@@ -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 {}

25
2018/src/day21.rs Normal file
View File

@@ -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 {}

25
2018/src/day22.rs Normal file
View File

@@ -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 {}

25
2018/src/day23.rs Normal file
View File

@@ -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 {}

25
2018/src/day24.rs Normal file
View File

@@ -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 {}

25
2018/src/day25.rs Normal file
View File

@@ -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 {}

View File

@@ -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<common::Solution> {
match day {
@@ -25,6 +43,22 @@ pub fn get_impl(day: u32) -> Box<common::Solution> {
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);
}

View File

@@ -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")