Address cargo clippy output.
This commit is contained in:
parent
5b65e8ec71
commit
45f780c1ca
@ -79,7 +79,7 @@ use aoc_runner_derive::{aoc, aoc_generator};
|
|||||||
/// Reads text file containing one integer per line, and parses them into `Vec<u32>`.
|
/// Reads text file containing one integer per line, and parses them into `Vec<u32>`.
|
||||||
#[aoc_generator(day1)]
|
#[aoc_generator(day1)]
|
||||||
fn parse(input: &str) -> Result<Vec<u32>> {
|
fn parse(input: &str) -> Result<Vec<u32>> {
|
||||||
input.split("\n").map(|s| Ok(s.parse()?)).collect()
|
input.split('\n').map(|s| Ok(s.parse()?)).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[aoc(day1, part1)]
|
#[aoc(day1, part1)]
|
||||||
|
|||||||
@ -59,8 +59,8 @@ use aoc_runner_derive::aoc;
|
|||||||
fn part1(input: &str) -> Result<i32> {
|
fn part1(input: &str) -> Result<i32> {
|
||||||
let mut horizontal: i32 = 0;
|
let mut horizontal: i32 = 0;
|
||||||
let mut depth: i32 = 0;
|
let mut depth: i32 = 0;
|
||||||
for l in input.split("\n") {
|
for l in input.split('\n') {
|
||||||
let p: Vec<_> = l.split(" ").collect();
|
let p: Vec<_> = l.split(' ').collect();
|
||||||
|
|
||||||
match p[0] {
|
match p[0] {
|
||||||
"forward" => horizontal += p[1].parse::<i32>()?,
|
"forward" => horizontal += p[1].parse::<i32>()?,
|
||||||
@ -77,8 +77,8 @@ fn part2(input: &str) -> Result<i32> {
|
|||||||
let mut horizontal: i32 = 0;
|
let mut horizontal: i32 = 0;
|
||||||
let mut depth: i32 = 0;
|
let mut depth: i32 = 0;
|
||||||
let mut aim: i32 = 0;
|
let mut aim: i32 = 0;
|
||||||
for l in input.split("\n") {
|
for l in input.split('\n') {
|
||||||
let p: Vec<_> = l.split(" ").collect();
|
let p: Vec<_> = l.split(' ').collect();
|
||||||
|
|
||||||
match p[0] {
|
match p[0] {
|
||||||
"forward" => {
|
"forward" => {
|
||||||
|
|||||||
@ -61,16 +61,14 @@
|
|||||||
//!
|
//!
|
||||||
//! Use the binary numbers in your diagnostic report to calculate the oxygen generator rating and CO2 scrubber rating, then multiply them together. What is the life support rating of the submarine? (Be sure to represent your answer in decimal, not binary.)
|
//! Use the binary numbers in your diagnostic report to calculate the oxygen generator rating and CO2 scrubber rating, then multiply them together. What is the life support rating of the submarine? (Be sure to represent your answer in decimal, not binary.)
|
||||||
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::{Debug, Error, Formatter};
|
||||||
use std::fmt::Error;
|
|
||||||
use std::fmt::Formatter;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use aoc_runner_derive::aoc;
|
use aoc_runner_derive::aoc;
|
||||||
|
|
||||||
#[aoc(day3, part1)]
|
#[aoc(day3, part1)]
|
||||||
fn part1(input: &str) -> Result<u64> {
|
fn part1(input: &str) -> Result<u64> {
|
||||||
let lines: Vec<_> = input.trim().split("\n").collect();
|
let lines: Vec<_> = input.trim().split('\n').collect();
|
||||||
let num_bits = lines[0].len();
|
let num_bits = lines[0].len();
|
||||||
let majority = lines.len() / 2;
|
let majority = lines.len() / 2;
|
||||||
let mut bits = vec![0; num_bits];
|
let mut bits = vec![0; num_bits];
|
||||||
@ -109,11 +107,11 @@ enum Partition {
|
|||||||
struct Binaries<'a>(&'a [u64]);
|
struct Binaries<'a>(&'a [u64]);
|
||||||
impl<'a> Debug for Binaries<'a> {
|
impl<'a> Debug for Binaries<'a> {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
|
||||||
write!(f, "[\n")?;
|
writeln!(f, "[")?;
|
||||||
for n in self.0.iter() {
|
for n in self.0.iter() {
|
||||||
write!(f, " 0b{:08b},\n", n)?;
|
writeln!(f, " 0b{:08b},", n)?;
|
||||||
}
|
}
|
||||||
write!(f, "]\n")?;
|
writeln!(f, "]")?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,18 +122,14 @@ fn partition(nums: &[u64], bit_offset: usize, partition_type: Partition) -> u64
|
|||||||
|
|
||||||
let remainder = match partition_type {
|
let remainder = match partition_type {
|
||||||
Partition::Oxygen => {
|
Partition::Oxygen => {
|
||||||
if one.len() == zero.len() {
|
if one.len() >= zero.len() {
|
||||||
one
|
|
||||||
} else if one.len() > zero.len() {
|
|
||||||
one
|
one
|
||||||
} else {
|
} else {
|
||||||
zero
|
zero
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Partition::CO2 => {
|
Partition::CO2 => {
|
||||||
if one.len() == zero.len() {
|
if one.len() >= zero.len() {
|
||||||
zero
|
|
||||||
} else if one.len() > zero.len() {
|
|
||||||
zero
|
zero
|
||||||
} else {
|
} else {
|
||||||
one
|
one
|
||||||
@ -150,7 +144,7 @@ fn partition(nums: &[u64], bit_offset: usize, partition_type: Partition) -> u64
|
|||||||
|
|
||||||
#[aoc(day3, part2)]
|
#[aoc(day3, part2)]
|
||||||
fn part2(input: &str) -> Result<u64> {
|
fn part2(input: &str) -> Result<u64> {
|
||||||
let lines: Vec<_> = input.trim().split("\n").collect();
|
let lines: Vec<_> = input.trim().split('\n').collect();
|
||||||
let nums: Vec<_> = lines
|
let nums: Vec<_> = lines
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| u64::from_str_radix(s, 2))
|
.map(|s| u64::from_str_radix(s, 2))
|
||||||
|
|||||||
@ -87,8 +87,6 @@ enum GameError {
|
|||||||
ParseIntError(#[from] ParseIntError),
|
ParseIntError(#[from] ParseIntError),
|
||||||
#[error("couldn't parse board {0}")]
|
#[error("couldn't parse board {0}")]
|
||||||
BoardError(#[from] BoardError),
|
BoardError(#[from] BoardError),
|
||||||
#[error("unknown")]
|
|
||||||
Unknown,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Game {
|
impl Game {
|
||||||
@ -130,7 +128,7 @@ impl FromStr for Game {
|
|||||||
let numbers = it
|
let numbers = it
|
||||||
.next()
|
.next()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.split(",")
|
.split(',')
|
||||||
.map(|s| s.parse())
|
.map(|s| s.parse())
|
||||||
.collect::<Result<_, ParseIntError>>()?;
|
.collect::<Result<_, ParseIntError>>()?;
|
||||||
let boards: Vec<_> = it.map(|s| s.parse()).collect::<Result<_, BoardError>>()?;
|
let boards: Vec<_> = it.map(|s| s.parse()).collect::<Result<_, BoardError>>()?;
|
||||||
@ -152,8 +150,6 @@ struct Board {
|
|||||||
enum BoardError {
|
enum BoardError {
|
||||||
#[error("couldn't parse number {0}")]
|
#[error("couldn't parse number {0}")]
|
||||||
ParseIntError(#[from] ParseIntError),
|
ParseIntError(#[from] ParseIntError),
|
||||||
#[error("unknown")]
|
|
||||||
Unknown,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Board {
|
impl Board {
|
||||||
@ -206,7 +202,7 @@ impl Debug for Board {
|
|||||||
write!(f, "{:3}", self.numbers[&(x, y)])?;
|
write!(f, "{:3}", self.numbers[&(x, y)])?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writeln!(f, "")?;
|
writeln!(f)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -217,11 +213,11 @@ impl FromStr for Board {
|
|||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
let numbers: Vec<Vec<_>> = s
|
let numbers: Vec<Vec<_>> = s
|
||||||
.split("\n")
|
.split('\n')
|
||||||
.map(|l| {
|
.map(|l| {
|
||||||
l.split(" ")
|
l.split(' ')
|
||||||
// Remove the double space that happens before single digit cells.
|
// Remove the double space that happens before single digit cells.
|
||||||
.filter(|c| *c != "")
|
.filter(|c| !c.is_empty())
|
||||||
.map(|c| c.parse())
|
.map(|c| c.parse())
|
||||||
.collect::<Result<_, ParseIntError>>()
|
.collect::<Result<_, ParseIntError>>()
|
||||||
})
|
})
|
||||||
|
|||||||
@ -105,11 +105,11 @@ impl FromStr for Line {
|
|||||||
type Err = LineError;
|
type Err = LineError;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
let mut it = s.split(" ");
|
let mut it = s.split(' ');
|
||||||
let parse_point = |it: &mut dyn Iterator<Item = &str>| -> Result<Point, LineError> {
|
let parse_point = |it: &mut dyn Iterator<Item = &str>| -> Result<Point, LineError> {
|
||||||
let p = it.next().ok_or(LineError::PrematureEOL)?;
|
let p = it.next().ok_or(LineError::PrematureEOL)?;
|
||||||
let nums: Vec<_> = p
|
let nums: Vec<_> = p
|
||||||
.split(",")
|
.split(',')
|
||||||
.map(|n| n.parse())
|
.map(|n| n.parse())
|
||||||
.collect::<Result<_, ParseIntError>>()?;
|
.collect::<Result<_, ParseIntError>>()?;
|
||||||
Ok(Point {
|
Ok(Point {
|
||||||
@ -178,7 +178,7 @@ impl Debug for Image {
|
|||||||
#[aoc_generator(day5)]
|
#[aoc_generator(day5)]
|
||||||
fn parse(input: &str) -> Result<Vec<Line>> {
|
fn parse(input: &str) -> Result<Vec<Line>> {
|
||||||
Ok(input
|
Ok(input
|
||||||
.split("\n")
|
.split('\n')
|
||||||
.map(|l| l.parse())
|
.map(|l| l.parse())
|
||||||
.collect::<Result<_, LineError>>()?)
|
.collect::<Result<_, LineError>>()?)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
use advent2021;
|
|
||||||
|
|
||||||
use aoc_runner_derive::aoc_main;
|
use aoc_runner_derive::aoc_main;
|
||||||
|
|
||||||
aoc_main! { lib = advent2021 }
|
aoc_main! { lib = advent2021 }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user