Change signature for solution.

This commit is contained in:
2019-08-22 12:28:52 +02:00
parent e949701564
commit 29b5dcdf62
26 changed files with 73 additions and 73 deletions

View File

@@ -112,7 +112,7 @@ pub fn trim_back(input: &mut Vec<u8>) {
/// Read the entire input as one value. /// Read the entire input as one value.
/// ///
/// This function loads the input into a string and then attempts to parse it. /// This function loads the input into a string and then attempts to parse it.
pub fn read_single_input<T>(input: &mut Read) -> T pub fn read_single_input<T>(input: &mut dyn Read) -> T
where where
T: FromStr, T: FromStr,
<T as FromStr>::Err: Debug, <T as FromStr>::Err: Debug,
@@ -158,10 +158,10 @@ where
/// be easily run from the main program. /// be easily run from the main program.
pub trait Solution { pub trait Solution {
/// Solve the first part of the day /// Solve the first part of the day
fn part1(&mut self, input: &mut io::Read) -> String; fn part1(&mut self, input: &mut dyn io::Read) -> String;
/// Solve the second part of the day /// Solve the second part of the day
fn part2(&mut self, input: &mut io::Read) -> String; fn part2(&mut self, input: &mut dyn io::Read) -> String;
} }
#[cfg(test)] #[cfg(test)]

View File

@@ -14,7 +14,7 @@ impl Day01 {
} }
impl common::Solution for Day01 { impl common::Solution for Day01 {
fn part1(&mut self, input: &mut io::Read) -> String { fn part1(&mut self, input: &mut dyn io::Read) -> String {
let reader = io::BufReader::new(input); let reader = io::BufReader::new(input);
let sum: i32 = reader let sum: i32 = reader
@@ -25,7 +25,7 @@ impl common::Solution for Day01 {
sum.to_string() sum.to_string()
} }
fn part2(&mut self, input: &mut io::Read) -> String { fn part2(&mut self, input: &mut dyn io::Read) -> String {
let reader = io::BufReader::new(input); let reader = io::BufReader::new(input);
let mut freqs = HashSet::new(); let mut freqs = HashSet::new();
freqs.insert(0); freqs.insert(0);

View File

@@ -33,7 +33,7 @@ impl Day02 {
} }
impl common::Solution for Day02 { impl common::Solution for Day02 {
fn part1(&mut self, input: &mut io::Read) -> String { fn part1(&mut self, input: &mut dyn io::Read) -> String {
let reader = io::BufReader::new(input); let reader = io::BufReader::new(input);
let mut twos = 0; let mut twos = 0;
let mut threes = 0; let mut threes = 0;
@@ -53,7 +53,7 @@ impl common::Solution for Day02 {
(twos * threes).to_string() (twos * threes).to_string()
} }
fn part2(&mut self, input: &mut io::Read) -> String { fn part2(&mut self, input: &mut dyn io::Read) -> String {
let mut ids: Vec<String> = io::BufReader::new(input) let mut ids: Vec<String> = io::BufReader::new(input)
.lines() .lines()
.map(|x| x.unwrap()) .map(|x| x.unwrap())

View File

@@ -40,7 +40,7 @@ impl Day03 {
Default::default() Default::default()
} }
fn read_claims(&mut self, input: &mut io::Read) { fn read_claims(&mut self, input: &mut dyn io::Read) {
let reader = io::BufReader::new(input); let reader = io::BufReader::new(input);
self.claims.clear(); self.claims.clear();
@@ -66,7 +66,7 @@ impl Day03 {
} }
impl common::Solution for Day03 { impl common::Solution for Day03 {
fn part1(&mut self, input: &mut io::Read) -> String { fn part1(&mut self, input: &mut dyn io::Read) -> String {
self.read_claims(input); self.read_claims(input);
let claim_map = self.get_claims(); let claim_map = self.get_claims();
@@ -75,7 +75,7 @@ impl common::Solution for Day03 {
multi_claim.to_string() multi_claim.to_string()
} }
fn part2(&mut self, input: &mut io::Read) -> String { fn part2(&mut self, input: &mut dyn io::Read) -> String {
self.read_claims(input); self.read_claims(input);
let claims = self.get_claims(); let claims = self.get_claims();

View File

@@ -33,7 +33,7 @@ impl Day04 {
Default::default() Default::default()
} }
fn read_events(&mut self, input: &mut io::Read) { fn read_events(&mut self, input: &mut dyn io::Read) {
self.events.clear(); self.events.clear();
let reader = io::BufReader::new(input); let reader = io::BufReader::new(input);
@@ -105,7 +105,7 @@ impl Day04 {
} }
impl common::Solution for Day04 { impl common::Solution for Day04 {
fn part1(&mut self, input: &mut io::Read) -> String { fn part1(&mut self, input: &mut dyn io::Read) -> String {
self.read_events(input); self.read_events(input);
let sleepers = self.get_sleeps(); let sleepers = self.get_sleeps();
let scores: HashMap<usize, u32> = let scores: HashMap<usize, u32> =
@@ -114,7 +114,7 @@ impl common::Solution for Day04 {
Day04::format_results(&sleepers, &scores) Day04::format_results(&sleepers, &scores)
} }
fn part2(&mut self, input: &mut io::Read) -> String { fn part2(&mut self, input: &mut dyn io::Read) -> String {
self.read_events(input); self.read_events(input);
let sleepers = self.get_sleeps(); let sleepers = self.get_sleeps();
let scores: HashMap<usize, u32> = sleepers let scores: HashMap<usize, u32> = sleepers

View File

@@ -29,7 +29,7 @@ impl Day05 {
} }
impl common::Solution for Day05 { impl common::Solution for Day05 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
let mut data = Vec::new(); let mut data = Vec::new();
input.read_to_end(&mut data).expect("Can't read input!"); input.read_to_end(&mut data).expect("Can't read input!");
common::trim_back(&mut data); common::trim_back(&mut data);
@@ -37,7 +37,7 @@ impl common::Solution for Day05 {
Day05::reduce(data).to_string() Day05::reduce(data).to_string()
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
let mut data = Vec::new(); let mut data = Vec::new();
input.read_to_end(&mut data).expect("Can't read input!"); input.read_to_end(&mut data).expect("Can't read input!");
common::trim_back(&mut data); common::trim_back(&mut data);

View File

@@ -28,7 +28,7 @@ impl Day06 {
Default::default() Default::default()
} }
pub fn read_points(&mut self, input: &mut Read) { pub fn read_points(&mut self, input: &mut dyn Read) {
let reader = BufReader::new(input); let reader = BufReader::new(input);
self.points.clear(); self.points.clear();
@@ -78,7 +78,7 @@ impl Day06 {
grid grid
} }
pub fn part2_with_limit(&mut self, input: &mut Read, limit: usize) -> usize { pub fn part2_with_limit(&mut self, input: &mut dyn Read, limit: usize) -> usize {
self.read_points(input); self.read_points(input);
self.range() self.range()
@@ -96,7 +96,7 @@ fn claim_filter(claim: &Claim) -> Option<usize> {
} }
impl Solution for Day06 { impl Solution for Day06 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
self.read_points(input); self.read_points(input);
let grid = self.compute_claim_grid(); let grid = self.compute_claim_grid();
let mut infinite: HashSet<usize> = HashSet::new(); let mut infinite: HashSet<usize> = HashSet::new();
@@ -121,7 +121,7 @@ impl Solution for Day06 {
counts.values().max().unwrap().to_string() counts.values().max().unwrap().to_string()
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
self.part2_with_limit(input, 10_000).to_string() self.part2_with_limit(input, 10_000).to_string()
} }
} }

View File

@@ -39,7 +39,7 @@ impl Day07 {
Default::default() Default::default()
} }
fn read_edges(&mut self, input: &mut Read) { fn read_edges(&mut self, input: &mut dyn Read) {
let reader = BufReader::new(input); let reader = BufReader::new(input);
let regex = Regex::new(r"Step (\w) must be finished before step (\w) can begin").unwrap(); let regex = Regex::new(r"Step (\w) must be finished before step (\w) can begin").unwrap();
@@ -56,7 +56,7 @@ impl Day07 {
fn part2_parametrized( fn part2_parametrized(
&mut self, &mut self,
input: &mut Read, input: &mut dyn Read,
base_time: usize, base_time: usize,
max_workers: usize, max_workers: usize,
) -> usize { ) -> usize {
@@ -108,7 +108,7 @@ impl Day07 {
} }
impl Solution for Day07 { impl Solution for Day07 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
self.read_edges(input); self.read_edges(input);
let mut result = String::new(); let mut result = String::new();
@@ -138,7 +138,7 @@ impl Solution for Day07 {
result result
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
self.part2_parametrized(input, 60, 5).to_string() self.part2_parametrized(input, 60, 5).to_string()
} }
} }

View File

@@ -57,7 +57,7 @@ impl Day08 {
} }
impl Solution for Day08 { impl Solution for Day08 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
let data: String = read_single_input(input); let data: String = read_single_input(input);
let data: Vec<usize> = data.trim().split(' ').map(|x| x.parse().unwrap()).collect(); let data: Vec<usize> = data.trim().split(' ').map(|x| x.parse().unwrap()).collect();
@@ -66,7 +66,7 @@ impl Solution for Day08 {
result.to_string() result.to_string()
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
let data: String = read_single_input(input); let data: String = read_single_input(input);
let data: Vec<usize> = data.trim().split(' ').map(|x| x.parse().unwrap()).collect(); let data: Vec<usize> = data.trim().split(' ').map(|x| x.parse().unwrap()).collect();

View File

@@ -40,7 +40,7 @@ impl Day09 {
Default::default() Default::default()
} }
fn read_input(input: &mut Read) -> (usize, usize) { fn read_input(input: &mut dyn Read) -> (usize, usize) {
let mut data = String::new(); let mut data = String::new();
input.read_to_string(&mut data).unwrap(); input.read_to_string(&mut data).unwrap();
let mut parts = data.split(' '); let mut parts = data.split(' ');
@@ -52,13 +52,13 @@ impl Day09 {
} }
impl Solution for Day09 { impl Solution for Day09 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
let (elves, marbles) = Day09::read_input(input); let (elves, marbles) = Day09::read_input(input);
winning_marbles(elves, marbles).to_string() winning_marbles(elves, marbles).to_string()
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
let (elves, marbles) = Day09::read_input(input); let (elves, marbles) = Day09::read_input(input);
winning_marbles(elves, marbles * 100).to_string() winning_marbles(elves, marbles * 100).to_string()

View File

@@ -21,7 +21,7 @@ impl Day10 {
Default::default() Default::default()
} }
fn read_inputs(&mut self, input: &mut Read) { fn read_inputs(&mut self, input: &mut dyn Read) {
let reader = BufReader::new(input); let reader = BufReader::new(input);
let matcher = let matcher =
Regex::new(r"position=<\s*(-?\d+),\s*(-?\d+)> velocity=<\s*(-?\d+),\s*(-?\d+)>") Regex::new(r"position=<\s*(-?\d+),\s*(-?\d+)> velocity=<\s*(-?\d+),\s*(-?\d+)>")
@@ -96,7 +96,7 @@ impl Day10 {
dist.checked_div(speed).unwrap_or(1).max(1) dist.checked_div(speed).unwrap_or(1).max(1)
} }
fn simulate(&mut self, input: &mut Read) -> i32 { fn simulate(&mut self, input: &mut dyn Read) -> i32 {
self.read_inputs(input); self.read_inputs(input);
let mut prev = self.height(); let mut prev = self.height();
let mut steps = self.underestimate_time(); let mut steps = self.underestimate_time();
@@ -115,12 +115,12 @@ impl Day10 {
} }
impl Solution for Day10 { impl Solution for Day10 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
self.simulate(input); self.simulate(input);
self.print_state() self.print_state()
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
self.simulate(input).to_string() self.simulate(input).to_string()
} }
} }

View File

@@ -93,7 +93,7 @@ impl Default for Day11 {
} }
impl Solution for Day11 { impl Solution for Day11 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
let serial = read_single_input(input); let serial = read_single_input(input);
self.compute_summed_area(serial); self.compute_summed_area(serial);
let (x, y, _) = self.best(3); let (x, y, _) = self.best(3);
@@ -101,7 +101,7 @@ impl Solution for Day11 {
format!("{},{}", x, y) format!("{},{}", x, y)
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
let serial = read_single_input(input); let serial = read_single_input(input);
self.compute_summed_area(serial); self.compute_summed_area(serial);
let mut best_result = 0; let mut best_result = 0;

View File

@@ -40,7 +40,7 @@ impl Day12 {
Default::default() Default::default()
} }
fn read_input(&mut self, input: &mut Read) -> State { fn read_input(&mut self, input: &mut dyn Read) -> State {
let state; let state;
let mut reader = BufReader::new(input); let mut reader = BufReader::new(input);
let mut line = String::new(); let mut line = String::new();
@@ -107,14 +107,14 @@ impl Day12 {
} }
impl Solution for Day12 { impl Solution for Day12 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
let mut state = self.read_input(input); let mut state = self.read_input(input);
state = self.simulate_n(state, 20); state = self.simulate_n(state, 20);
self.sum(&state).to_string() self.sum(&state).to_string()
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
// Note: this is way too slow // Note: this is way too slow
let mut state = self.read_input(input); let mut state = self.read_input(input);
let mut seen = HashMap::new(); let mut seen = HashMap::new();

View File

@@ -98,7 +98,7 @@ impl Day13 {
self.carts.iter().filter(|x| x.alive).count() self.carts.iter().filter(|x| x.alive).count()
} }
fn read_input(&mut self, input: &mut Read) { fn read_input(&mut self, input: &mut dyn Read) {
let reader = BufReader::new(input); let reader = BufReader::new(input);
for (y, line) in reader.lines().enumerate() { for (y, line) in reader.lines().enumerate() {
let line = line.unwrap(); let line = line.unwrap();
@@ -183,7 +183,7 @@ impl Day13 {
} }
impl Solution for Day13 { impl Solution for Day13 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
self.read_input(input); self.read_input(input);
let mut collision = None; let mut collision = None;
while collision == None { while collision == None {
@@ -193,7 +193,7 @@ impl Solution for Day13 {
format!("{},{}", x, y) format!("{},{}", x, y)
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
self.read_input(input); self.read_input(input);
while self.alive() > 1 { while self.alive() > 1 {
self.simulate(); self.simulate();

View File

@@ -76,12 +76,12 @@ impl Day14 {
} }
impl Solution for Day14 { impl Solution for Day14 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
let input = read_single_input(input); let input = read_single_input(input);
format!("{:010}", skill_after(input)) format!("{:010}", skill_after(input))
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
let mut buf = String::new(); let mut buf = String::new();
input.read_to_string(&mut buf).unwrap(); input.read_to_string(&mut buf).unwrap();

View File

@@ -48,7 +48,7 @@ impl Day15 {
Default::default() Default::default()
} }
fn read_input(&mut self, input: &mut Read) { fn read_input(&mut self, input: &mut dyn Read) {
let reader = BufReader::new(input); let reader = BufReader::new(input);
for (y, line) in reader.lines().enumerate() { for (y, line) in reader.lines().enumerate() {
@@ -212,7 +212,7 @@ impl Day15 {
} }
impl Solution for Day15 { impl Solution for Day15 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
self.read_input(input); self.read_input(input);
let mut rounds = 0; let mut rounds = 0;
while self.simulate() { while self.simulate() {
@@ -221,7 +221,7 @@ impl Solution for Day15 {
self.return_score(rounds) self.return_score(rounds)
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
self.read_input(input); self.read_input(input);
let backup = self.units.clone(); let backup = self.units.clone();
let starting_elves = self.alive[0]; let starting_elves = self.alive[0];

View File

@@ -40,7 +40,7 @@ impl Day16 {
fn determine_options( fn determine_options(
&mut self, &mut self,
mut reader: &mut BufReader<&mut Read>, mut reader: &mut BufReader<&mut dyn Read>,
) -> [HashSet<OpCode>; 16] { ) -> [HashSet<OpCode>; 16] {
let mut mappings: [HashSet<OpCode>; 16] = [ let mut mappings: [HashSet<OpCode>; 16] = [
HashSet::new(), HashSet::new(),
@@ -119,7 +119,7 @@ impl Default for Day16 {
} }
impl Solution for Day16 { impl Solution for Day16 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
let mut reader = BufReader::new(input); let mut reader = BufReader::new(input);
let mut before = [0; 6]; let mut before = [0; 6];
@@ -143,7 +143,7 @@ impl Solution for Day16 {
counter.to_string() counter.to_string()
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
let mut reader = BufReader::new(input); let mut reader = BufReader::new(input);
let mappings = self.determine_options(&mut reader); let mappings = self.determine_options(&mut reader);

View File

@@ -25,7 +25,7 @@ impl Day17 {
Default::default() Default::default()
} }
fn read_input(&mut self, input: &mut Read) { fn read_input(&mut self, input: &mut dyn Read) {
let matcher = Regex::new(r"(.)=(\d+), (.)=(\d+)\.\.(\d+)").unwrap(); let matcher = Regex::new(r"(.)=(\d+), (.)=(\d+)\.\.(\d+)").unwrap();
let reader = BufReader::new(input); let reader = BufReader::new(input);
@@ -119,7 +119,7 @@ impl Day17 {
} }
impl Solution for Day17 { impl Solution for Day17 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
self.read_input(input); self.read_input(input);
self.descend((500, 0)); self.descend((500, 0));
@@ -128,7 +128,7 @@ impl Solution for Day17 {
result.to_string() result.to_string()
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
self.read_input(input); self.read_input(input);
self.descend((500, 0)); self.descend((500, 0));

View File

@@ -78,7 +78,7 @@ impl Day18 {
Default::default() Default::default()
} }
fn read_input(&mut self, input: &mut Read) { fn read_input(&mut self, input: &mut dyn Read) {
let reader = BufReader::new(input); let reader = BufReader::new(input);
self.grid.clear(); self.grid.clear();
@@ -141,7 +141,7 @@ impl Day18 {
} }
impl Solution for Day18 { impl Solution for Day18 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
self.read_input(input); self.read_input(input);
for _ in 0..10 { for _ in 0..10 {
@@ -151,7 +151,7 @@ impl Solution for Day18 {
self.score() self.score()
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
self.read_input(input); self.read_input(input);
let limit = 1_000_000_000; let limit = 1_000_000_000;

View File

@@ -17,7 +17,7 @@ impl Day19 {
Default::default() Default::default()
} }
fn read_input(&mut self, input: &mut Read) { fn read_input(&mut self, input: &mut dyn Read) {
let reader = BufReader::new(input); let reader = BufReader::new(input);
for line in reader.lines() { for line in reader.lines() {
@@ -39,7 +39,7 @@ impl Day19 {
} }
impl Solution for Day19 { impl Solution for Day19 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
self.read_input(input); self.read_input(input);
let mut cpu = CPU::new(); let mut cpu = CPU::new();
@@ -53,7 +53,7 @@ impl Solution for Day19 {
cpu.registers[0].to_string() cpu.registers[0].to_string()
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
self.read_input(input); self.read_input(input);
let mut cpu = CPU::new(); let mut cpu = CPU::new();

View File

@@ -137,7 +137,7 @@ impl Day20 {
} }
impl Solution for Day20 { impl Solution for Day20 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
let mut data = Vec::new(); let mut data = Vec::new();
input.read_to_end(&mut data).unwrap(); input.read_to_end(&mut data).unwrap();
let pos = (0, 0); let pos = (0, 0);
@@ -146,7 +146,7 @@ impl Solution for Day20 {
self.distances().values().max().unwrap().to_string() self.distances().values().max().unwrap().to_string()
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
let mut data = Vec::new(); let mut data = Vec::new();
input.read_to_end(&mut data).unwrap(); input.read_to_end(&mut data).unwrap();
let pos = (0, 0); let pos = (0, 0);

View File

@@ -48,11 +48,11 @@ impl Day21 {
} }
impl Solution for Day21 { impl Solution for Day21 {
fn part1(&mut self, _input: &mut Read) -> String { fn part1(&mut self, _input: &mut dyn Read) -> String {
ValidInputs::new(0).next().unwrap().to_string() ValidInputs::new(0).next().unwrap().to_string()
} }
fn part2(&mut self, _input: &mut Read) -> String { fn part2(&mut self, _input: &mut dyn Read) -> String {
let inputs = ValidInputs::new(0); let inputs = ValidInputs::new(0);
let mut seen = HashSet::new(); let mut seen = HashSet::new();
let mut last: Option<i64> = None; let mut last: Option<i64> = None;

View File

@@ -63,7 +63,7 @@ fn compute_table((x, y): Coordinate, depth: usize) -> Vec<Vec<usize>> {
table table
} }
fn read_input(input: &mut Read) -> (usize, Coordinate) { fn read_input(input: &mut dyn Read) -> (usize, Coordinate) {
let mut buf = String::new(); let mut buf = String::new();
let mut reader = BufReader::new(input); let mut reader = BufReader::new(input);
reader.read_line(&mut buf).unwrap(); reader.read_line(&mut buf).unwrap();
@@ -88,7 +88,7 @@ fn read_input(input: &mut Read) -> (usize, Coordinate) {
} }
impl Solution for Day22 { impl Solution for Day22 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
let (depth, target) = read_input(input); let (depth, target) = read_input(input);
let mut table = compute_table(target, depth); let mut table = compute_table(target, depth);
table[target.1][target.0] = 0; table[target.1][target.0] = 0;
@@ -97,7 +97,7 @@ impl Solution for Day22 {
result.to_string() result.to_string()
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
let (depth, target) = read_input(input); let (depth, target) = read_input(input);
let mut table = compute_table((target.0 + 200, target.1 + 200), depth); let mut table = compute_table((target.0 + 200, target.1 + 200), depth);
table[target.1][target.0] = 0; table[target.1][target.0] = 0;

View File

@@ -72,7 +72,7 @@ impl Day23 {
Default::default() Default::default()
} }
fn read_input(&mut self, input: &mut Read) { fn read_input(&mut self, input: &mut dyn Read) {
let matcher = Regex::new(r"-?\d+").unwrap(); let matcher = Regex::new(r"-?\d+").unwrap();
let reader = BufReader::new(input); let reader = BufReader::new(input);
@@ -92,7 +92,7 @@ impl Day23 {
} }
impl Solution for Day23 { impl Solution for Day23 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
self.read_input(input); self.read_input(input);
self.bots.sort_unstable(); self.bots.sort_unstable();
let (best_range, best_pos) = *self.bots.last().unwrap(); let (best_range, best_pos) = *self.bots.last().unwrap();
@@ -106,7 +106,7 @@ impl Solution for Day23 {
result.to_string() result.to_string()
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
self.read_input(input); self.read_input(input);
let mut neighbours = vec![HashSet::new(); self.bots.len()]; let mut neighbours = vec![HashSet::new(); self.bots.len()];

View File

@@ -52,7 +52,7 @@ impl Day24 {
Default::default() Default::default()
} }
fn read_input(&mut self, input: &mut Read) { fn read_input(&mut self, input: &mut dyn Read) {
let matcher = Regex::new(r"(\d+) units each with (\d+) hit points (\(([^)]+)\) )?with an attack that does (\d+) (\w+) damage at initiative (\d+)").unwrap(); let matcher = Regex::new(r"(\d+) units each with (\d+) hit points (\(([^)]+)\) )?with an attack that does (\d+) (\w+) damage at initiative (\d+)").unwrap();
let weakness_matcher = Regex::new(r"(weak|immune) to ([^;)]+)").unwrap(); let weakness_matcher = Regex::new(r"(weak|immune) to ([^;)]+)").unwrap();
let reader = BufReader::new(input); let reader = BufReader::new(input);
@@ -194,7 +194,7 @@ impl Day24 {
} }
impl Solution for Day24 { impl Solution for Day24 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
self.read_input(input); self.read_input(input);
self.full_simulation(); self.full_simulation();
@@ -202,7 +202,7 @@ impl Solution for Day24 {
result.to_string() result.to_string()
} }
fn part2(&mut self, input: &mut Read) -> String { fn part2(&mut self, input: &mut dyn Read) -> String {
self.read_input(input); self.read_input(input);
let original = self.units.clone(); let original = self.units.clone();

View File

@@ -17,7 +17,7 @@ impl Day25 {
Default::default() Default::default()
} }
fn read_input(&mut self, input: &mut Read) { fn read_input(&mut self, input: &mut dyn Read) {
let matcher = Regex::new(r"-?\d+").unwrap(); let matcher = Regex::new(r"-?\d+").unwrap();
let reader = BufReader::new(input); let reader = BufReader::new(input);
@@ -79,12 +79,12 @@ impl Day25 {
} }
impl Solution for Day25 { impl Solution for Day25 {
fn part1(&mut self, input: &mut Read) -> String { fn part1(&mut self, input: &mut dyn Read) -> String {
self.read_input(input); self.read_input(input);
self.connected_components().to_string() self.connected_components().to_string()
} }
fn part2(&mut self, _input: &mut Read) -> String { fn part2(&mut self, _input: &mut dyn Read) -> String {
// As always, no part 2 for day 25. // As always, no part 2 for day 25.
String::new() String::new()
} }