Skip to content

Commit

Permalink
Rename the Solution trait's associated types
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadiac committed Dec 9, 2023
1 parent d60e9a7 commit 3e1fc05
Show file tree
Hide file tree
Showing 80 changed files with 206 additions and 206 deletions.
8 changes: 4 additions & 4 deletions aoc-solver/src/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ impl std::fmt::Display for AocError {
}

pub trait Solution {
type F: fmt::Display;
type S: fmt::Display;
type A: fmt::Display;
type B: fmt::Display;

fn default_input(&self) -> &'static str;

fn part_1(&self, input: &str) -> Result<Self::F, AocError>;
fn part_2(&self, input: &str) -> Result<Self::S, AocError>;
fn part_1(&self, input: &str) -> Result<Self::A, AocError>;
fn part_2(&self, input: &str) -> Result<Self::B, AocError>;

fn run(&self, input: Option<String>, day: u32, year: u32) -> Vec<String> {
let input = input.unwrap_or_else(|| self.default_input().to_owned());
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::solution::{AocError, Solution};
pub struct Day01;

impl Solution for Day01 {
type F = usize;
type S = usize;
type A = usize;
type B = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day01.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ fn parse_input(input: &str) -> Vec<DatabaseRow> {
}

impl Solution for Day02 {
type F = usize;
type S = usize;
type A = usize;
type B = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day02.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ fn parse(input: &str) -> (HashSet<(usize, usize)>, usize, usize) {
}

impl Solution for Day03 {
type F = usize;
type S = usize;
type A = usize;
type B = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day03.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ fn parse_passport_part2(input: &str) -> IResult<&str, Passport> {
}

impl Solution for Day04 {
type F = usize;
type S = usize;
type A = usize;
type B = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day04.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ fn parse_boarding_pass(input: &str) -> BoardingPass {
}

impl Solution for Day05 {
type F = usize;
type S = usize;
type A = usize;
type B = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day05.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ fn parse_answers_2(input: &str) -> HashSet<char> {
}

impl Solution for Day06 {
type F = usize;
type S = usize;
type A = usize;
type B = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day06.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day07.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ fn find_inner_bags_count(current: String, rules: HashMap<String, Rule>) -> usize
}

impl Solution for Day07 {
type F = usize;
type S = usize;
type A = usize;
type B = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day07.txt")
Expand Down
8 changes: 4 additions & 4 deletions aoc-solver/src/y2020/day08.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ fn parse_instruction(input: &str) -> IResult<&str, Instruction> {
}

impl Solution for Day08 {
type F = i32;
type S = i32;
type A = i32;
type B = i32;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day08.txt")
}

fn part_1(&self, input: &str) -> Result<Self::F, AocError> {
fn part_1(&self, input: &str) -> Result<i32, AocError> {
let instructions: Vec<Instruction> = input
.lines()
.filter_map(|line| parse_instruction(line).ok())
Expand All @@ -111,7 +111,7 @@ impl Solution for Day08 {
Ok(console.accumulator)
}

fn part_2(&self, input: &str) -> Result<Self::S, AocError> {
fn part_2(&self, input: &str) -> Result<i32, AocError> {
let corrupted_instructions: Vec<Instruction> = input
.lines()
.filter_map(|line| parse_instruction(line).ok())
Expand Down
8 changes: 4 additions & 4 deletions aoc-solver/src/y2020/day09.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ fn solve_part2(input: &str, preamble_len: usize) -> Result<usize, AocError> {
}

impl Solution for Day09 {
type F = usize;
type S = usize;
type A = usize;
type B = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day09.txt")
}

fn part_1(&self, input: &str) -> Result<Self::F, AocError> {
fn part_1(&self, input: &str) -> Result<usize, AocError> {
solve_part1(input, 25)
}

fn part_2(&self, input: &str) -> Result<Self::S, AocError> {
fn part_2(&self, input: &str) -> Result<usize, AocError> {
solve_part2(input, 25)
}
}
Expand Down
8 changes: 4 additions & 4 deletions aoc-solver/src/y2020/day10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,21 @@ impl Solver {
}

impl Solution for Day10 {
type F = i64;
type S = i64;
type A = i64;
type B = i64;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day10.txt")
}

fn part_1(&self, input: &str) -> Result<Self::F, AocError> {
fn part_1(&self, input: &str) -> Result<i64, AocError> {
let solver = Solver::new(input);
let result = solver.part_1();

Ok(result)
}

fn part_2(&self, input: &str) -> Result<Self::S, AocError> {
fn part_2(&self, input: &str) -> Result<i64, AocError> {
let mut solver = Solver::new(input);
let result = solver.part_2();

Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ impl GameOfSeats {
}

impl Solution for Day11 {
type F = usize;
type S = usize;
type A = usize;
type B = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day11.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub struct Ship {
}

impl Solution for Day12 {
type F = i32;
type S = i32;
type A = i32;
type B = i32;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day12.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day13.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ fn mod_inv(a: i64, module: i64) -> i64 {
}

impl Solution for Day13 {
type F = i64;
type S = i64;
type A = i64;
type B = i64;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day13.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day14.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::solution::{AocError, Solution};
pub struct Day14;

impl Solution for Day14 {
type F = u64;
type S = u64;
type A = u64;
type B = u64;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day14.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day15.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ fn memory_game(input: &str, turns: u32) -> u32 {
}

impl Solution for Day15 {
type F = u32;
type S = u32;
type A = u32;
type B = u32;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day15.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ fn parse_part_2(input: &str) -> Option<(Ticket, Vec<TicketField>)> {
}

impl Solution for Day16 {
type F = u64;
type S = u64;
type A = u64;
type B = u64;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day16.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day17.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ impl GameOfCubes {
}

impl Solution for Day17 {
type F = usize;
type S = usize;
type A = usize;
type B = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day17.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day18.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ fn evaluate_rpn(mut rpn: VecDeque<char>) -> i64 {
}

impl Solution for Day18 {
type F = i64;
type S = i64;
type A = i64;
type B = i64;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day18.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day19.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ fn count_valid_grammar(input: &str) -> usize {
}

impl Solution for Day19 {
type F = usize;
type S = usize;
type A = usize;
type B = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day19.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ impl Solver {
}

impl Solution for Day20 {
type F = u64;
type S = usize;
type A = u64;
type B = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day20.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day21.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ fn parse_line(input: &str) -> (HashSet<&str>, HashSet<&str>) {
}

impl Solution for Day21 {
type F = usize;
type S = String;
type A = usize;
type B = String;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day21.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day22.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ fn play_recursive_game(
}

impl Solution for Day22 {
type F = usize;
type S = usize;
type A = usize;
type B = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day22.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day23.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ fn play(input: &str, moves: u32) -> Result<String, AocError> {
}

impl Solution for Day23 {
type F = String;
type S = u64;
type A = String;
type B = u64;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day23.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day24.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ impl GameOfTiles {
}

impl Solution for Day24 {
type F = usize;
type S = usize;
type A = usize;
type B = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day24.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2020/day25.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ fn transform_subject_num(subject_number: u64, loop_size: u64) -> u64 {
}

impl Solution for Day25 {
type F = u64;
type S = String;
type A = u64;
type B = String;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day01.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2021/day01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ where
}

impl Solution for Day01 {
type F = usize;
type S = usize;
type A = usize;
type B = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2021/day01.txt")
Expand Down
8 changes: 4 additions & 4 deletions aoc-solver/src/y2021/day02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use crate::solution::{AocError, Solution};
pub struct Day02;

impl Solution for Day02 {
type F = i32;
type S = i32;
type A = i32;
type B = i32;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2021/day02.txt")
}

fn part_1(&self, input: &str) -> Result<Self::F, AocError> {
fn part_1(&self, input: &str) -> Result<i32, AocError> {
let mut position: (i32, i32) = (0, 0);

for command in input.lines() {
Expand All @@ -28,7 +28,7 @@ impl Solution for Day02 {
Ok(position.0 * position.1)
}

fn part_2(&self, input: &str) -> Result<Self::S, AocError> {
fn part_2(&self, input: &str) -> Result<i32, AocError> {
let mut position: (i32, i32) = (0, 0);
let mut aim = 0;

Expand Down
Loading

0 comments on commit 3e1fc05

Please sign in to comment.