Compare commits

...

2 Commits

Author SHA1 Message Date
777b9dce30 Remove unnecessary pub modifiers 2022-12-07 13:30:08 -06:00
49ba314218 Remove unused import 2022-12-07 13:28:07 -06:00
6 changed files with 34 additions and 34 deletions

View File

@ -1,7 +1,7 @@
use aoc_runner_derive::{aoc, aoc_generator}; use aoc_runner_derive::{aoc, aoc_generator};
#[aoc_generator(day1)] #[aoc_generator(day1)]
pub fn input_generator(input: &str) -> Vec<Vec<u64>> { fn input_generator(input: &str) -> Vec<Vec<u64>> {
input input
.lines() .lines()
.collect::<Vec<_>>() .collect::<Vec<_>>()
@ -11,14 +11,14 @@ pub fn input_generator(input: &str) -> Vec<Vec<u64>> {
} }
#[aoc(day1, part1)] #[aoc(day1, part1)]
pub fn solve_part1(input: &[Vec<u64>]) -> u64 { fn solve_part1(input: &[Vec<u64>]) -> u64 {
let mut sums = input.iter().map(|el| el.iter().sum()).collect::<Vec<_>>(); let mut sums = input.iter().map(|el| el.iter().sum()).collect::<Vec<_>>();
sums.sort(); sums.sort();
sums.pop().unwrap() sums.pop().unwrap()
} }
#[aoc(day1, part2)] #[aoc(day1, part2)]
pub fn solve_part2(input: &[Vec<u64>]) -> u64 { fn solve_part2(input: &[Vec<u64>]) -> u64 {
let mut sums = input.iter().map(|el| el.iter().sum()).collect::<Vec<_>>(); let mut sums = input.iter().map(|el| el.iter().sum()).collect::<Vec<_>>();
sums.sort(); sums.sort();
sums[sums.len() - 3..sums.len()].iter().sum() sums[sums.len() - 3..sums.len()].iter().sum()

View File

@ -3,10 +3,10 @@ use std::str::FromStr;
use aoc_runner_derive::{aoc, aoc_generator}; use aoc_runner_derive::{aoc, aoc_generator};
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub struct InvalidMove; struct InvalidMove;
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Move { enum Move {
Rock, Rock,
Paper, Paper,
Scissors, Scissors,
@ -50,7 +50,7 @@ impl FromStr for Move {
} }
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Outcome { enum Outcome {
Lose, Lose,
Draw, Draw,
Win, Win,
@ -75,7 +75,7 @@ impl Outcome {
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub struct InvalidOutcome; struct InvalidOutcome;
impl FromStr for Outcome { impl FromStr for Outcome {
type Err = InvalidOutcome; type Err = InvalidOutcome;
@ -91,7 +91,7 @@ impl FromStr for Outcome {
} }
#[aoc_generator(day2, part1)] #[aoc_generator(day2, part1)]
pub fn input_generator_part1(input: &str) -> Vec<(Move, Move)> { fn input_generator_part1(input: &str) -> Vec<(Move, Move)> {
input input
.lines() .lines()
.map(|line| { .map(|line| {
@ -102,7 +102,7 @@ pub fn input_generator_part1(input: &str) -> Vec<(Move, Move)> {
} }
#[aoc(day2, part1)] #[aoc(day2, part1)]
pub fn solve_part1(input: &[(Move, Move)]) -> u64 { fn solve_part1(input: &[(Move, Move)]) -> u64 {
input input
.iter() .iter()
.map(|&(opp, you)| you.shape_score() + you.round_score(opp)) .map(|&(opp, you)| you.shape_score() + you.round_score(opp))
@ -110,7 +110,7 @@ pub fn solve_part1(input: &[(Move, Move)]) -> u64 {
} }
#[aoc_generator(day2, part2)] #[aoc_generator(day2, part2)]
pub fn input_generator_part2(input: &str) -> Vec<(Move, Outcome)> { fn input_generator_part2(input: &str) -> Vec<(Move, Outcome)> {
input input
.lines() .lines()
.map(|line| { .map(|line| {
@ -121,7 +121,7 @@ pub fn input_generator_part2(input: &str) -> Vec<(Move, Outcome)> {
} }
#[aoc(day2, part2)] #[aoc(day2, part2)]
pub fn solve_part2(input: &[(Move, Outcome)]) -> u64 { fn solve_part2(input: &[(Move, Outcome)]) -> u64 {
input input
.iter() .iter()
.map(|&(opp, outcome)| { .map(|&(opp, outcome)| {

View File

@ -3,16 +3,16 @@ use std::str::FromStr;
use aoc_runner_derive::{aoc, aoc_generator}; use aoc_runner_derive::{aoc, aoc_generator};
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct Rucksack { struct Rucksack {
first_half: Vec<u8>, first_half: Vec<u8>,
second_half: Vec<u8>, second_half: Vec<u8>,
} }
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct NoItemInBothHalves; struct NoItemInBothHalves;
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct NoCommonItem; struct NoCommonItem;
impl Rucksack { impl Rucksack {
fn find_item_in_both_halves(&self) -> Result<u8, NoItemInBothHalves> { fn find_item_in_both_halves(&self) -> Result<u8, NoItemInBothHalves> {
@ -38,7 +38,7 @@ impl Rucksack {
} }
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct InvalidRucksack; struct InvalidRucksack;
impl FromStr for Rucksack { impl FromStr for Rucksack {
type Err = InvalidRucksack; type Err = InvalidRucksack;
@ -65,12 +65,12 @@ impl FromStr for Rucksack {
} }
#[aoc_generator(day3, part1)] #[aoc_generator(day3, part1)]
pub fn input_generator_part1(input: &str) -> Vec<Rucksack> { fn input_generator_part1(input: &str) -> Vec<Rucksack> {
input.lines().map(|l| l.parse().unwrap()).collect() input.lines().map(|l| l.parse().unwrap()).collect()
} }
#[aoc_generator(day3, part2)] #[aoc_generator(day3, part2)]
pub fn input_generator_part2(input: &str) -> Vec<Vec<Rucksack>> { fn input_generator_part2(input: &str) -> Vec<Vec<Rucksack>> {
input input
.lines() .lines()
.collect::<Vec<_>>() .collect::<Vec<_>>()
@ -84,7 +84,7 @@ pub fn input_generator_part2(input: &str) -> Vec<Vec<Rucksack>> {
} }
#[aoc(day3, part1)] #[aoc(day3, part1)]
pub fn solve_part1(input: &[Rucksack]) -> u64 { fn solve_part1(input: &[Rucksack]) -> u64 {
input input
.iter() .iter()
.map(|rucksack| rucksack.find_item_in_both_halves().unwrap() as u64) .map(|rucksack| rucksack.find_item_in_both_halves().unwrap() as u64)
@ -92,7 +92,7 @@ pub fn solve_part1(input: &[Rucksack]) -> u64 {
} }
#[aoc(day3, part2)] #[aoc(day3, part2)]
pub fn solve_part2(input: &[Vec<Rucksack>]) -> u64 { fn solve_part2(input: &[Vec<Rucksack>]) -> u64 {
input input
.iter() .iter()
.map(|rucksacks| rucksacks[0].find_common_item(&rucksacks[1..]).unwrap() as u64) .map(|rucksacks| rucksacks[0].find_common_item(&rucksacks[1..]).unwrap() as u64)

View File

@ -8,7 +8,7 @@ fn parse_range(range: &str) -> RangeInclusive<u64> {
} }
#[aoc_generator(day4)] #[aoc_generator(day4)]
pub fn input_generator(input: &str) -> Vec<(RangeInclusive<u64>, RangeInclusive<u64>)> { fn input_generator(input: &str) -> Vec<(RangeInclusive<u64>, RangeInclusive<u64>)> {
input input
.lines() .lines()
.map(|l| { .map(|l| {
@ -27,7 +27,7 @@ fn overlaps_with_range(slf: &RangeInclusive<u64>, other: &RangeInclusive<u64>) -
} }
#[aoc(day4, part1)] #[aoc(day4, part1)]
pub fn solve_part1(input: &[(RangeInclusive<u64>, RangeInclusive<u64>)]) -> usize { fn solve_part1(input: &[(RangeInclusive<u64>, RangeInclusive<u64>)]) -> usize {
input input
.iter() .iter()
.filter(|(first, second)| contains_range(first, second) | contains_range(second, first)) .filter(|(first, second)| contains_range(first, second) | contains_range(second, first))
@ -35,7 +35,7 @@ pub fn solve_part1(input: &[(RangeInclusive<u64>, RangeInclusive<u64>)]) -> usiz
} }
#[aoc(day4, part2)] #[aoc(day4, part2)]
pub fn solve_part2(input: &[(RangeInclusive<u64>, RangeInclusive<u64>)]) -> usize { fn solve_part2(input: &[(RangeInclusive<u64>, RangeInclusive<u64>)]) -> usize {
input input
.iter() .iter()
.filter(|(first, second)| { .filter(|(first, second)| {

View File

@ -3,25 +3,25 @@ use std::str::FromStr;
use aoc_runner_derive::{aoc, aoc_generator}; use aoc_runner_derive::{aoc, aoc_generator};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Stacks { struct Stacks {
stacks: Vec<Vec<char>>, stacks: Vec<Vec<char>>,
} }
impl Stacks { impl Stacks {
pub fn apply_instruction(&mut self, ins: &Instruction) { fn apply_instruction(&mut self, ins: &Instruction) {
for _ in 0..(ins.count) { for _ in 0..(ins.count) {
let crte = self.stacks[ins.from - 1].pop().unwrap(); let crte = self.stacks[ins.from - 1].pop().unwrap();
self.stacks[ins.to - 1].push(crte); self.stacks[ins.to - 1].push(crte);
} }
} }
pub fn apply_instruction_in_order(&mut self, ins: &Instruction) { fn apply_instruction_in_order(&mut self, ins: &Instruction) {
let from_stack = &mut self.stacks[ins.from - 1]; let from_stack = &mut self.stacks[ins.from - 1];
let crates = from_stack.split_off(from_stack.len() - ins.count); let crates = from_stack.split_off(from_stack.len() - ins.count);
self.stacks[ins.to - 1].extend_from_slice(&crates); self.stacks[ins.to - 1].extend_from_slice(&crates);
} }
pub fn top_crates(&self) -> String { fn top_crates(&self) -> String {
self.stacks self.stacks
.iter() .iter()
.map(|stack| stack.last().unwrap()) .map(|stack| stack.last().unwrap())
@ -30,7 +30,7 @@ impl Stacks {
} }
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct InvalidStacks; struct InvalidStacks;
impl FromStr for Stacks { impl FromStr for Stacks {
type Err = InvalidStacks; type Err = InvalidStacks;
@ -59,14 +59,14 @@ impl FromStr for Stacks {
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Instruction { struct Instruction {
count: usize, count: usize,
from: usize, from: usize,
to: usize, to: usize,
} }
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct InvalidInstruction; struct InvalidInstruction;
impl FromStr for Instruction { impl FromStr for Instruction {
type Err = InvalidInstruction; type Err = InvalidInstruction;
@ -85,7 +85,7 @@ impl FromStr for Instruction {
} }
#[aoc_generator(day5)] #[aoc_generator(day5)]
pub fn input_generator(input: &str) -> (Stacks, Vec<Instruction>) { fn input_generator(input: &str) -> (Stacks, Vec<Instruction>) {
let (start, instructions) = input.split_once(&"\n\n").unwrap(); let (start, instructions) = input.split_once(&"\n\n").unwrap();
( (
start.parse().unwrap(), start.parse().unwrap(),
@ -97,7 +97,7 @@ pub fn input_generator(input: &str) -> (Stacks, Vec<Instruction>) {
} }
#[aoc(day5, part1)] #[aoc(day5, part1)]
pub fn solve_part1(input: &(Stacks, Vec<Instruction>)) -> String { fn solve_part1(input: &(Stacks, Vec<Instruction>)) -> String {
let mut stacks = input.0.clone(); let mut stacks = input.0.clone();
for ins in &input.1 { for ins in &input.1 {
stacks.apply_instruction(ins); stacks.apply_instruction(ins);
@ -106,7 +106,7 @@ pub fn solve_part1(input: &(Stacks, Vec<Instruction>)) -> String {
} }
#[aoc(day5, part2)] #[aoc(day5, part2)]
pub fn solve_part2(input: &(Stacks, Vec<Instruction>)) -> String { fn solve_part2(input: &(Stacks, Vec<Instruction>)) -> String {
let mut stacks = input.0.clone(); let mut stacks = input.0.clone();
for ins in &input.1 { for ins in &input.1 {
stacks.apply_instruction_in_order(ins); stacks.apply_instruction_in_order(ins);

View File

@ -1,4 +1,4 @@
use std::{path::PathBuf, str::FromStr}; use std::str::FromStr;
use aoc_runner_derive::{aoc, aoc_generator}; use aoc_runner_derive::{aoc, aoc_generator};
use id_tree::{InsertBehavior, Node, Tree}; use id_tree::{InsertBehavior, Node, Tree};
@ -26,7 +26,7 @@ impl DirectoryEntry {
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub struct InvalidDirectoryEntry; struct InvalidDirectoryEntry;
impl FromStr for DirectoryEntry { impl FromStr for DirectoryEntry {
type Err = InvalidDirectoryEntry; type Err = InvalidDirectoryEntry;