Skip to content

Commit

Permalink
Bit of refactoring, fixing clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadiac committed Dec 27, 2024
1 parent f9ed53c commit f64a345
Show file tree
Hide file tree
Showing 121 changed files with 296 additions and 279 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 A: fmt::Display;
type B: fmt::Display;
type Part1: fmt::Display;
type Part2: fmt::Display;

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

fn part_1(&self, input: &str) -> Result<Self::A, AocError>;
fn part_2(&self, input: &str) -> Result<Self::B, AocError>;
fn part_1(&self, input: &str) -> Result<Self::Part1, AocError>;
fn part_2(&self, input: &str) -> Result<Self::Part2, 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 A = usize;
type B = usize;
type Part1 = usize;
type Part2 = 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 A = usize;
type B = usize;
type Part1 = usize;
type Part2 = 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 A = usize;
type B = usize;
type Part1 = usize;
type Part2 = 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 A = usize;
type B = usize;
type Part1 = usize;
type Part2 = 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 A = usize;
type B = usize;
type Part1 = usize;
type Part2 = 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 A = usize;
type B = usize;
type Part1 = usize;
type Part2 = 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 A = usize;
type B = usize;
type Part1 = usize;
type Part2 = usize;

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

impl Solution for Day08 {
type A = i32;
type B = i32;
type Part1 = i32;
type Part2 = i32;

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

impl Solution for Day09 {
type A = usize;
type B = usize;
type Part1 = usize;
type Part2 = usize;

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

impl Solution for Day10 {
type A = i64;
type B = i64;
type Part1 = i64;
type Part2 = i64;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2020/day10.txt")
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 A = usize;
type B = usize;
type Part1 = usize;
type Part2 = 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 A = i32;
type B = i32;
type Part1 = i32;
type Part2 = 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 A = i64;
type B = i64;
type Part1 = i64;
type Part2 = 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 A = u64;
type B = u64;
type Part1 = u64;
type Part2 = 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 A = u32;
type B = u32;
type Part1 = u32;
type Part2 = 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 A = u64;
type B = u64;
type Part1 = u64;
type Part2 = 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 A = usize;
type B = usize;
type Part1 = usize;
type Part2 = 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 A = i64;
type B = i64;
type Part1 = i64;
type Part2 = 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 A = usize;
type B = usize;
type Part1 = usize;
type Part2 = usize;

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

fn check_for_sea_monsters(data: &mut Vec<Vec<(char, bool)>>) {
fn check_for_sea_monsters(data: &mut [Vec<(char, bool)>]) {
// A sea monster will look like this:
// #
// # ## ## ###
Expand Down Expand Up @@ -282,8 +282,8 @@ impl Solver {
}

impl Solution for Day20 {
type A = u64;
type B = usize;
type Part1 = u64;
type Part2 = 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 A = usize;
type B = String;
type Part1 = usize;
type Part2 = 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 A = usize;
type B = usize;
type Part1 = usize;
type Part2 = 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 A = String;
type B = u64;
type Part1 = String;
type Part2 = 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 A = usize;
type B = usize;
type Part1 = usize;
type Part2 = 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 A = u64;
type B = String;
type Part1 = u64;
type Part2 = 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 A = usize;
type B = usize;
type Part1 = usize;
type Part2 = usize;

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

impl Solution for Day02 {
type A = i32;
type B = i32;
type Part1 = i32;
type Part2 = i32;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2021/day02.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2021/day03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ fn filter_by_bit_criteria(mut candidates: Vec<Vec<u32>>, expected_value: u32) ->
}

impl Solution for Day03 {
type A = u32;
type B = u32;
type Part1 = u32;
type Part2 = u32;

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

impl Solution for Day04 {
type A = usize;
type B = usize;
type Part1 = usize;
type Part2 = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2021/day04.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2021/day05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ fn solve(input: &str, is_allow_diagonal: bool) -> usize {
}

impl Solution for Day05 {
type A = usize;
type B = usize;
type Part1 = usize;
type Part2 = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2021/day05.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2021/day06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ fn solve(input: &str, days: usize) -> u64 {
}

impl Solution for Day06 {
type A = u64;
type B = u64;
type Part1 = u64;
type Part2 = u64;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2021/day06.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2021/day07.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ fn parse(input: &str) -> Vec<usize> {
}

impl Solution for Day07 {
type A = usize;
type B = usize;
type Part1 = usize;
type Part2 = usize;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2021/day07.txt")
Expand Down
4 changes: 2 additions & 2 deletions aoc-solver/src/y2021/day08.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ fn signal_to_decimal_mappings(unique_signal_patterns: Vec<HashSet<char>>) -> Has
}

impl Solution for Day08 {
type A = usize;
type B = u32;
type Part1 = usize;
type Part2 = u32;

fn default_input(&self) -> &'static str {
include_str!("../../../inputs/2021/day08.txt")
Expand Down
Loading

0 comments on commit f64a345

Please sign in to comment.