clippy changes

This commit is contained in:
kageru 2020-12-04 18:36:43 +01:00
parent 1f011f9826
commit 8f7fc726bc
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
4 changed files with 8 additions and 7 deletions

View File

@ -10,7 +10,7 @@ fn read_input() -> Vec<usize> {
.collect()
}
fn part1(input: &Vec<usize>) -> usize {
fn part1(input: &[usize]) -> usize {
input
.iter()
.tuple_combinations()
@ -18,7 +18,7 @@ fn part1(input: &Vec<usize>) -> usize {
.unwrap()
}
fn part2(input: &Vec<usize>) -> usize {
fn part2(input: &[usize]) -> usize {
let mut p2_table = [None; 2020];
for (&a, &b) in input.iter().tuple_combinations() {
if a + b < 2020 {
@ -26,7 +26,7 @@ fn part2(input: &Vec<usize>) -> usize {
}
}
let (a, b) = input.iter().find_map(|x| p2_table[2020 - x]).unwrap();
return a * b * (2020 - a - b);
a * b * (2020 - a - b)
}
fn main() {

View File

@ -53,6 +53,7 @@ fn main() {
println!("{}", p2);
}
#[cfg(test)]
mod tests {
use super::*;

View File

@ -14,8 +14,8 @@ type Forest = Vec<Vec<Tile>>;
const STEP_RIGHT: [usize; 5] = [1, 3, 5, 7, 1];
const STEP_DOWN: [usize; 5] = [1, 1, 1, 1, 2];
const TREE: u8 = '#' as u8;
const FREE: u8 = '.' as u8;
const TREE: u8 = b'#';
const FREE: u8 = b'.';
impl From<u8> for Tile {
#[inline]
@ -95,7 +95,7 @@ mod tests {
// branch-free version of if x >= width { x -= width }
x -= width * ((x >= width) as usize);
}
return trees;
trees
}
#[test]

View File

@ -51,7 +51,7 @@ lazy_static! {
static ref PID_REGEX: Regex = Regex::new(r"^\d{9}$").unwrap();
}
fn part2(ps: &Vec<Passport>) -> usize {
fn part2(ps: &[Passport]) -> usize {
ps.iter()
.filter(|p| {
p.byr >= 1920