2019: fix new clippy lints
This commit is contained in:
parent
deb808faf3
commit
9a2e37468f
|
@ -190,7 +190,7 @@ impl FromStr for Move {
|
||||||
fn from_str(s: &str) -> Result<Self> {
|
fn from_str(s: &str) -> Result<Self> {
|
||||||
let direction = s
|
let direction = s
|
||||||
.chars()
|
.chars()
|
||||||
.nth(0)
|
.next()
|
||||||
.context("couldn't get direction char in move")?;
|
.context("couldn't get direction char in move")?;
|
||||||
|
|
||||||
let s = s.get(1..).context("move missing length")?;
|
let s = s.get(1..).context("move missing length")?;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::cmp::Ordering;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
@ -59,16 +60,20 @@ fn part2(begin: usize, end: usize) -> Result<usize> {
|
||||||
let mut count = 1;
|
let mut count = 1;
|
||||||
let mut prev = digits[0];
|
let mut prev = digits[0];
|
||||||
for digit in digits.iter().skip(1) {
|
for digit in digits.iter().skip(1) {
|
||||||
if prev > *digit {
|
match prev.cmp(digit) {
|
||||||
ordered = false;
|
Ordering::Greater => {
|
||||||
break;
|
ordered = false;
|
||||||
} else if prev == *digit {
|
break;
|
||||||
count += 1;
|
}
|
||||||
} else {
|
Ordering::Equal => {
|
||||||
if count == 2 {
|
count += 1;
|
||||||
pair = true;
|
}
|
||||||
|
Ordering::Less => {
|
||||||
|
if count == 2 {
|
||||||
|
pair = true;
|
||||||
|
}
|
||||||
|
count = 1;
|
||||||
}
|
}
|
||||||
count = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prev = *digit;
|
prev = *digit;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::cmp::Ordering;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
@ -52,28 +53,40 @@ fn part1(mut planets: Vec<Planet>, steps: usize) -> Result<u64> {
|
||||||
let first = &mut begin[pair.0];
|
let first = &mut begin[pair.0];
|
||||||
let second = &mut end[0];
|
let second = &mut end[0];
|
||||||
|
|
||||||
if first.position.x > second.position.x {
|
match first.position.x.cmp(&second.position.x) {
|
||||||
first.velocity.x -= 1;
|
Ordering::Greater => {
|
||||||
second.velocity.x += 1;
|
first.velocity.x -= 1;
|
||||||
} else if first.position.x < second.position.x {
|
second.velocity.x += 1;
|
||||||
first.velocity.x += 1;
|
}
|
||||||
second.velocity.x -= 1;
|
Ordering::Less => {
|
||||||
|
first.velocity.x += 1;
|
||||||
|
second.velocity.x -= 1;
|
||||||
|
}
|
||||||
|
Ordering::Equal => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if first.position.y > second.position.y {
|
match first.position.y.cmp(&second.position.y) {
|
||||||
first.velocity.y -= 1;
|
Ordering::Greater => {
|
||||||
second.velocity.y += 1;
|
first.velocity.y -= 1;
|
||||||
} else if first.position.y < second.position.y {
|
second.velocity.y += 1;
|
||||||
first.velocity.y += 1;
|
}
|
||||||
second.velocity.y -= 1;
|
Ordering::Less => {
|
||||||
|
first.velocity.y += 1;
|
||||||
|
second.velocity.y -= 1;
|
||||||
|
}
|
||||||
|
Ordering::Equal => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if first.position.z > second.position.z {
|
match first.position.z.cmp(&second.position.z) {
|
||||||
first.velocity.z -= 1;
|
Ordering::Greater => {
|
||||||
second.velocity.z += 1;
|
first.velocity.z -= 1;
|
||||||
} else if first.position.z < second.position.z {
|
second.velocity.z += 1;
|
||||||
first.velocity.z += 1;
|
}
|
||||||
second.velocity.z -= 1;
|
Ordering::Less => {
|
||||||
|
first.velocity.z += 1;
|
||||||
|
second.velocity.z -= 1;
|
||||||
|
}
|
||||||
|
Ordering::Equal => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,28 +127,40 @@ fn part2(mut planets: Vec<Planet>) -> Result<usize> {
|
||||||
let first = &mut begin[pair.0];
|
let first = &mut begin[pair.0];
|
||||||
let second = &mut end[0];
|
let second = &mut end[0];
|
||||||
|
|
||||||
if first.position.x > second.position.x {
|
match first.position.x.cmp(&second.position.x) {
|
||||||
first.velocity.x -= 1;
|
Ordering::Greater => {
|
||||||
second.velocity.x += 1;
|
first.velocity.x -= 1;
|
||||||
} else if first.position.x < second.position.x {
|
second.velocity.x += 1;
|
||||||
first.velocity.x += 1;
|
}
|
||||||
second.velocity.x -= 1;
|
Ordering::Less => {
|
||||||
|
first.velocity.x += 1;
|
||||||
|
second.velocity.x -= 1;
|
||||||
|
}
|
||||||
|
Ordering::Equal => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if first.position.y > second.position.y {
|
match first.position.y.cmp(&second.position.y) {
|
||||||
first.velocity.y -= 1;
|
Ordering::Greater => {
|
||||||
second.velocity.y += 1;
|
first.velocity.y -= 1;
|
||||||
} else if first.position.y < second.position.y {
|
second.velocity.y += 1;
|
||||||
first.velocity.y += 1;
|
}
|
||||||
second.velocity.y -= 1;
|
Ordering::Less => {
|
||||||
|
first.velocity.y += 1;
|
||||||
|
second.velocity.y -= 1;
|
||||||
|
}
|
||||||
|
Ordering::Equal => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if first.position.z > second.position.z {
|
match first.position.z.cmp(&second.position.z) {
|
||||||
first.velocity.z -= 1;
|
Ordering::Greater => {
|
||||||
second.velocity.z += 1;
|
first.velocity.z -= 1;
|
||||||
} else if first.position.z < second.position.z {
|
second.velocity.z += 1;
|
||||||
first.velocity.z += 1;
|
}
|
||||||
second.velocity.z -= 1;
|
Ordering::Less => {
|
||||||
|
first.velocity.z += 1;
|
||||||
|
second.velocity.z -= 1;
|
||||||
|
}
|
||||||
|
Ordering::Equal => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::cmp::Ordering;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt::{self, Display, Write};
|
use std::fmt::{self, Display, Write};
|
||||||
|
|
||||||
|
@ -30,13 +31,7 @@ fn part1(memory: Vec<i64>) -> Result<usize> {
|
||||||
map.insert(pos, tile);
|
map.insert(pos, tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(map
|
Ok(map.values().filter(|t| matches!(t, Tile::Block)).count())
|
||||||
.values()
|
|
||||||
.filter(|t| match t {
|
|
||||||
Tile::Block => true,
|
|
||||||
_ => false,
|
|
||||||
})
|
|
||||||
.count())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
@ -50,12 +45,10 @@ fn print_screen(screen: &[Vec<Tile>]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_next_move(paddle_pos: (i64, i64), ball_pos: (i64, i64)) -> i64 {
|
fn get_next_move(paddle_pos: (i64, i64), ball_pos: (i64, i64)) -> i64 {
|
||||||
if ball_pos.0 > paddle_pos.0 {
|
match ball_pos.0.cmp(&paddle_pos.0) {
|
||||||
1
|
Ordering::Greater => 1,
|
||||||
} else if ball_pos.0 == paddle_pos.0 {
|
Ordering::Equal => 0,
|
||||||
0
|
Ordering::Less => -1,
|
||||||
} else {
|
|
||||||
-1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ fn get_ore_cost(
|
||||||
in_stock += num_reactions * recipe.produced;
|
in_stock += num_reactions * recipe.produced;
|
||||||
}
|
}
|
||||||
|
|
||||||
inventory.insert(material.clone(), in_stock - quantity);
|
inventory.insert(material, in_stock - quantity);
|
||||||
|
|
||||||
Ok(total)
|
Ok(total)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue