Fix other clippy warnings.

This commit is contained in:
2019-08-22 12:32:07 +02:00
parent 29b5dcdf62
commit 82dfff21e9
10 changed files with 31 additions and 37 deletions

View File

@@ -76,7 +76,7 @@ impl Day04 {
sleep_start = Some(event.time); sleep_start = Some(event.time);
} }
EventType::WAKE => { EventType::WAKE => {
let mut minutes = sleeps.entry(guard.unwrap()).or_insert([0u32; 60]); let minutes = sleeps.entry(guard.unwrap()).or_insert([0u32; 60]);
for m in sleep_start.unwrap().minute()..event.time.minute() { for m in sleep_start.unwrap().minute()..event.time.minute() {
minutes[m as usize] += 1; minutes[m as usize] += 1;
} }

View File

@@ -54,6 +54,19 @@ impl Day07 {
} }
} }
fn schedule_dependents(&mut self, c: char, starting_points: &mut BinaryHeap<Reverse<char>>) {
if let Some(dependents) = self.forward.get(&c) {
for d in dependents {
let entry = self.dep_count.get_mut(d).unwrap();
if *entry == 1 {
starting_points.push(Reverse(*d));
} else {
*entry -= 1;
}
}
}
}
fn part2_parametrized( fn part2_parametrized(
&mut self, &mut self,
input: &mut dyn Read, input: &mut dyn Read,
@@ -85,17 +98,7 @@ impl Day07 {
while let Some(worker) = workers.pop() { while let Some(worker) = workers.pop() {
if worker.time == time { if worker.time == time {
let c = worker.work; let c = worker.work;
self.schedule_dependents(c, &mut starting_points);
if let Some(dependents) = self.forward.get(&c) {
for d in dependents {
let mut entry = self.dep_count.get_mut(d).unwrap();
if *entry == 1 {
starting_points.push(Reverse(*d));
} else {
*entry -= 1;
}
}
}
} else { } else {
workers.push(worker); workers.push(worker);
break; break;
@@ -122,17 +125,7 @@ impl Solution for Day07 {
while let Some(Reverse(c)) = starting_points.pop() { while let Some(Reverse(c)) = starting_points.pop() {
result.push(c); result.push(c);
self.schedule_dependents(c, &mut starting_points);
if let Some(dependents) = self.forward.get(&c) {
for d in dependents {
let mut entry = self.dep_count.get_mut(d).unwrap();
if *entry == 1 {
starting_points.push(Reverse(*d));
} else {
*entry -= 1;
}
}
}
} }
result result

View File

@@ -22,7 +22,7 @@ impl Day16 {
} }
} }
fn read(&mut self, reader: &mut BufRead, target: &mut [i32]) -> bool { fn read(&mut self, reader: &mut impl BufRead, target: &mut [i32]) -> bool {
self.buf.clear(); self.buf.clear();
if reader.read_line(&mut self.buf).is_err() { if reader.read_line(&mut self.buf).is_err() {
return false; return false;

View File

@@ -22,7 +22,7 @@ impl Day19 {
for line in reader.lines() { for line in reader.lines() {
let line = line.unwrap(); let line = line.unwrap();
if line.chars().next().unwrap() == '#' { if line.starts_with('#') {
self.ip = line.split(' ').last().unwrap().parse().unwrap(); self.ip = line.split(' ').last().unwrap().parse().unwrap();
} else { } else {
let mut parts = line.split(' '); let mut parts = line.split(' ');

View File

@@ -1,3 +1,4 @@
use std::collections::hash_map::Entry;
use std::collections::HashMap; use std::collections::HashMap;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::io::Read; use std::io::Read;
@@ -124,8 +125,8 @@ impl Day20 {
}); });
for dir in dirs { for dir in dirs {
let new_pos = dir.walk(pos); let new_pos = dir.walk(pos);
if !visited.contains_key(&new_pos) { if let Entry::Vacant(entry) = visited.entry(new_pos) {
visited.insert(new_pos, dist + 1); entry.insert(dist + 1);
todo.push_back((dist + 1, new_pos)); todo.push_back((dist + 1, new_pos));
} }
} }

View File

@@ -22,14 +22,14 @@ impl Iterator for ValidInputs {
fn next(&mut self) -> Option<i64> { fn next(&mut self) -> Option<i64> {
let mut f = self.f; let mut f = self.f;
let mut e = f | 0x10000; let mut e = f | 0x10000;
f = 13284195; f = 13_284_195;
loop { loop {
let d = e & 0xff; let d = e & 0xff;
f += d; f += d;
f &= 0xffffff; f &= 0xff_ffff;
f *= 65899; f *= 65899;
f &= 0xffffff; f &= 0xff_ffff;
if 0x100 > e { if 0x100 > e {
self.f = f; self.f = f;

View File

@@ -42,12 +42,12 @@ impl Day22 {
fn compute_table((x, y): Coordinate, depth: usize) -> Vec<Vec<usize>> { fn compute_table((x, y): Coordinate, depth: usize) -> Vec<Vec<usize>> {
let mut table = vec![vec![0usize; x + 1]; y + 1]; let mut table = vec![vec![0usize; x + 1]; y + 1];
table[0][0] = 0; table[0][0] = 0;
for x in 1..=x { for (x, entry) in table[0].iter_mut().enumerate().skip(1) {
table[0][x] = (16807 * x + depth) % MOD_BASE; *entry = (16807 * x + depth) % MOD_BASE;
} }
for y in 1..=y { for (y, entry) in table.iter_mut().enumerate().skip(1) {
table[y][0] = (48271 * y + depth) % MOD_BASE; entry[0] = (48271 * y + depth) % MOD_BASE;
} }
for y in 1..=y { for y in 1..=y {

View File

@@ -171,7 +171,7 @@ impl Day24 {
seen = Some(unit.faction); seen = Some(unit.faction);
} }
return false; false
} }
fn full_simulation(&mut self) { fn full_simulation(&mut self) {

View File

@@ -31,7 +31,7 @@ pub mod day23;
pub mod day24; pub mod day24;
pub mod day25; pub mod day25;
pub fn get_impl(day: u32) -> Box<common::Solution> { pub fn get_impl(day: u32) -> Box<dyn common::Solution> {
match day { match day {
1 => Box::new(day01::Day01::new()), 1 => Box::new(day01::Day01::new()),
2 => Box::new(day02::Day02::new()), 2 => Box::new(day02::Day02::new()),

View File

@@ -42,7 +42,7 @@ fn main() {
.get_matches(); .get_matches();
let mut implementation = get_impl(value_t_or_exit!(matches, "day", u32)); let mut implementation = get_impl(value_t_or_exit!(matches, "day", u32));
let mut data: Box<io::Read> = match matches.value_of("input") { let mut data: Box<dyn io::Read> = match matches.value_of("input") {
Some(filename) => Box::new(fs::File::open(filename).unwrap()), Some(filename) => Box::new(fs::File::open(filename).unwrap()),
None => Box::new(io::stdin()), None => Box::new(io::stdin()),
}; };