mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 12:50:32 +01:00
Fix other clippy warnings.
This commit is contained in:
@@ -76,7 +76,7 @@ impl Day04 {
|
||||
sleep_start = Some(event.time);
|
||||
}
|
||||
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() {
|
||||
minutes[m as usize] += 1;
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
&mut self,
|
||||
input: &mut dyn Read,
|
||||
@@ -85,17 +98,7 @@ impl Day07 {
|
||||
while let Some(worker) = workers.pop() {
|
||||
if worker.time == time {
|
||||
let c = worker.work;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.schedule_dependents(c, &mut starting_points);
|
||||
} else {
|
||||
workers.push(worker);
|
||||
break;
|
||||
@@ -122,17 +125,7 @@ impl Solution for Day07 {
|
||||
|
||||
while let Some(Reverse(c)) = starting_points.pop() {
|
||||
result.push(c);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.schedule_dependents(c, &mut starting_points);
|
||||
}
|
||||
|
||||
result
|
||||
|
||||
@@ -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();
|
||||
if reader.read_line(&mut self.buf).is_err() {
|
||||
return false;
|
||||
|
||||
@@ -22,7 +22,7 @@ impl Day19 {
|
||||
|
||||
for line in reader.lines() {
|
||||
let line = line.unwrap();
|
||||
if line.chars().next().unwrap() == '#' {
|
||||
if line.starts_with('#') {
|
||||
self.ip = line.split(' ').last().unwrap().parse().unwrap();
|
||||
} else {
|
||||
let mut parts = line.split(' ');
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::VecDeque;
|
||||
use std::io::Read;
|
||||
@@ -124,8 +125,8 @@ impl Day20 {
|
||||
});
|
||||
for dir in dirs {
|
||||
let new_pos = dir.walk(pos);
|
||||
if !visited.contains_key(&new_pos) {
|
||||
visited.insert(new_pos, dist + 1);
|
||||
if let Entry::Vacant(entry) = visited.entry(new_pos) {
|
||||
entry.insert(dist + 1);
|
||||
todo.push_back((dist + 1, new_pos));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ impl Iterator for ValidInputs {
|
||||
fn next(&mut self) -> Option<i64> {
|
||||
let mut f = self.f;
|
||||
let mut e = f | 0x10000;
|
||||
f = 13284195;
|
||||
f = 13_284_195;
|
||||
|
||||
loop {
|
||||
let d = e & 0xff;
|
||||
f += d;
|
||||
f &= 0xffffff;
|
||||
f &= 0xff_ffff;
|
||||
f *= 65899;
|
||||
f &= 0xffffff;
|
||||
f &= 0xff_ffff;
|
||||
|
||||
if 0x100 > e {
|
||||
self.f = f;
|
||||
|
||||
@@ -42,12 +42,12 @@ impl Day22 {
|
||||
fn compute_table((x, y): Coordinate, depth: usize) -> Vec<Vec<usize>> {
|
||||
let mut table = vec![vec![0usize; x + 1]; y + 1];
|
||||
table[0][0] = 0;
|
||||
for x in 1..=x {
|
||||
table[0][x] = (16807 * x + depth) % MOD_BASE;
|
||||
for (x, entry) in table[0].iter_mut().enumerate().skip(1) {
|
||||
*entry = (16807 * x + depth) % MOD_BASE;
|
||||
}
|
||||
|
||||
for y in 1..=y {
|
||||
table[y][0] = (48271 * y + depth) % MOD_BASE;
|
||||
for (y, entry) in table.iter_mut().enumerate().skip(1) {
|
||||
entry[0] = (48271 * y + depth) % MOD_BASE;
|
||||
}
|
||||
|
||||
for y in 1..=y {
|
||||
|
||||
@@ -171,7 +171,7 @@ impl Day24 {
|
||||
seen = Some(unit.faction);
|
||||
}
|
||||
|
||||
return false;
|
||||
false
|
||||
}
|
||||
|
||||
fn full_simulation(&mut self) {
|
||||
|
||||
@@ -31,7 +31,7 @@ pub mod day23;
|
||||
pub mod day24;
|
||||
pub mod day25;
|
||||
|
||||
pub fn get_impl(day: u32) -> Box<common::Solution> {
|
||||
pub fn get_impl(day: u32) -> Box<dyn common::Solution> {
|
||||
match day {
|
||||
1 => Box::new(day01::Day01::new()),
|
||||
2 => Box::new(day02::Day02::new()),
|
||||
|
||||
@@ -42,7 +42,7 @@ fn main() {
|
||||
.get_matches();
|
||||
|
||||
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()),
|
||||
None => Box::new(io::stdin()),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user