mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Bunch of clippy fixes
This commit is contained in:
@@ -11,7 +11,7 @@ use criterion::Criterion;
|
|||||||
const DAYS_IMPLEMENTED: u8 = 25;
|
const DAYS_IMPLEMENTED: u8 = 25;
|
||||||
|
|
||||||
fn read_input(day: u8) -> std::io::Result<Vec<u8>> {
|
fn read_input(day: u8) -> std::io::Result<Vec<u8>> {
|
||||||
let input_path = format!("inputs/{:02}.txt", day);
|
let input_path = format!("inputs/{day:02}.txt");
|
||||||
|
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
File::open(input_path)?.read_to_end(&mut buffer)?;
|
File::open(input_path)?.read_to_end(&mut buffer)?;
|
||||||
|
|||||||
@@ -182,8 +182,7 @@ impl IndexSet {
|
|||||||
|
|
||||||
self.0
|
self.0
|
||||||
.get(entry)
|
.get(entry)
|
||||||
.map(|&entry| (entry & (1 << pos) != 0))
|
.map_or(false, |&entry| (entry & (1 << pos) != 0))
|
||||||
.unwrap_or(false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,14 +84,14 @@ fn parse_program(input: &[u8]) -> IResult<&[u8], (u32, Vec<u32>)> {
|
|||||||
pub fn part1(input: &[u8]) -> Result<String> {
|
pub fn part1(input: &[u8]) -> Result<String> {
|
||||||
let (_, sizes) = parse_input(input, parse_program)?;
|
let (_, sizes) = parse_input(input, parse_program)?;
|
||||||
|
|
||||||
let searched_size: u32 = sizes.into_iter().filter(|&size| size <= 100000).sum();
|
let searched_size: u32 = sizes.into_iter().filter(|&size| size <= 100_000).sum();
|
||||||
|
|
||||||
Ok(searched_size.to_string())
|
Ok(searched_size.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn part2(input: &[u8]) -> Result<String> {
|
pub fn part2(input: &[u8]) -> Result<String> {
|
||||||
const TARGET: u32 = 30000000;
|
const TARGET: u32 = 30_000_000;
|
||||||
const TOTAL: u32 = 70000000;
|
const TOTAL: u32 = 70_000_000;
|
||||||
|
|
||||||
let (used, sizes) = parse_input(input, parse_program)?;
|
let (used, sizes) = parse_input(input, parse_program)?;
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ impl Monkey {
|
|||||||
// Miraculously get less worried
|
// Miraculously get less worried
|
||||||
new_val /= 3;
|
new_val /= 3;
|
||||||
|
|
||||||
drains[(new_val % self.test_mod == 0) as usize].push(new_val);
|
drains[usize::from(new_val % self.test_mod == 0)].push(new_val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ impl Monkey {
|
|||||||
// Modular arithmetic is a good way to get less worried
|
// Modular arithmetic is a good way to get less worried
|
||||||
new_val = new_val % mod_base;
|
new_val = new_val % mod_base;
|
||||||
|
|
||||||
drains[(new_val % self.test_mod == 0) as usize].push(new_val);
|
drains[usize::from(new_val % self.test_mod == 0)].push(new_val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ fn part1_generic<const Y: i32>(input: &[u8]) -> Result<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn part1(input: &[u8]) -> Result<String> {
|
pub fn part1(input: &[u8]) -> Result<String> {
|
||||||
part1_generic::<2000000>(input)
|
part1_generic::<2_000_000>(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2_generic<const MAX: i32>(input: &[u8]) -> Result<String> {
|
fn part2_generic<const MAX: i32>(input: &[u8]) -> Result<String> {
|
||||||
@@ -153,11 +153,11 @@ fn part2_generic<const MAX: i32>(input: &[u8]) -> Result<String> {
|
|||||||
|
|
||||||
let Vec2([x, y]) = find_unseen::<MAX>(&beacons)?;
|
let Vec2([x, y]) = find_unseen::<MAX>(&beacons)?;
|
||||||
|
|
||||||
Ok((i64::from(x) * 4000000 + i64::from(y)).to_string())
|
Ok((i64::from(x) * 4_000_000 + i64::from(y)).to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn part2(input: &[u8]) -> Result<String> {
|
pub fn part2(input: &[u8]) -> Result<String> {
|
||||||
part2_generic::<4000000>(input)
|
part2_generic::<4_000_000>(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ impl From<ParsedNetwork<'_>> for SimpleNetwork {
|
|||||||
.map(|(_, flow, connected)| {
|
.map(|(_, flow, connected)| {
|
||||||
let connected = connected.into_iter().map(|name| mapping[&name]).collect();
|
let connected = connected.into_iter().map(|name| mapping[&name]).collect();
|
||||||
|
|
||||||
SimpleValve { flow, connected }
|
SimpleValve { connected, flow }
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
start: mapping[&b"AA"[..]],
|
start: mapping[&b"AA"[..]],
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ pub fn part2(input: &[u8]) -> Result<String> {
|
|||||||
let mut tortoise_time = 0;
|
let mut tortoise_time = 0;
|
||||||
let mut last_gust = 0;
|
let mut last_gust = 0;
|
||||||
|
|
||||||
const TARGET: usize = 1000000000000;
|
const TARGET: usize = 1_000_000_000_000;
|
||||||
|
|
||||||
for (it, (shape_id, &shape)) in shapes.by_ref().enumerate() {
|
for (it, (shape_id, &shape)) in shapes.by_ref().enumerate() {
|
||||||
let mut x = 2usize;
|
let mut x = 2usize;
|
||||||
|
|||||||
@@ -105,17 +105,13 @@ impl BluePrint {
|
|||||||
machines,
|
machines,
|
||||||
}) = todo.pop()
|
}) = todo.pop()
|
||||||
{
|
{
|
||||||
let ideal_from_now = ideal(time_left as u32);
|
let ideal_from_now = ideal(u32::from(time_left));
|
||||||
// Need to check again because we might've gotten a better result in the meantime.
|
// Need to check again because we might've gotten a better result in the meantime.
|
||||||
if u32::from(best - got) >= ideal_from_now {
|
if u32::from(best - got) >= ideal_from_now {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if todo.len() > 1_000_000 {
|
assert!(todo.len() <= 1_000_000, "Safety: got a todo list of len {}, best: {best}",
|
||||||
panic!(
|
todo.len());
|
||||||
"Safety: got a todo list of len {}, best: {best}",
|
|
||||||
todo.len()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
for (element, &costs) in self.costs.iter().enumerate() {
|
for (element, &costs) in self.costs.iter().enumerate() {
|
||||||
let Some(min_to_build) = self.until_buildable(costs, resources, machines) else { break };
|
let Some(min_to_build) = self.until_buildable(costs, resources, machines) else { break };
|
||||||
|
|
||||||
@@ -161,7 +157,7 @@ impl BluePrint {
|
|||||||
|
|
||||||
let mut new_machines = machines;
|
let mut new_machines = machines;
|
||||||
new_machines[element] += 1;
|
new_machines[element] += 1;
|
||||||
let new_missed = ideal_from_now - ideal(time_after as u32);
|
let new_missed = ideal_from_now - ideal(u32::from(time_after));
|
||||||
todo.push(State {
|
todo.push(State {
|
||||||
missed: new_missed,
|
missed: new_missed,
|
||||||
got,
|
got,
|
||||||
@@ -249,7 +245,7 @@ pub fn part1(input: &[u8]) -> Result<String> {
|
|||||||
|
|
||||||
Ok(blueprints
|
Ok(blueprints
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|bp| bp.max_geodes(24) as u32 * bp.id)
|
.map(|bp| u32::from(bp.max_geodes(24)) * bp.id)
|
||||||
.sum::<u32>()
|
.sum::<u32>()
|
||||||
.to_string())
|
.to_string())
|
||||||
}
|
}
|
||||||
@@ -260,7 +256,7 @@ pub fn part2(input: &[u8]) -> Result<String> {
|
|||||||
let result: u32 = blueprints
|
let result: u32 = blueprints
|
||||||
.iter()
|
.iter()
|
||||||
.take(3)
|
.take(3)
|
||||||
.map(|bp| bp.max_geodes(32) as u32)
|
.map(|bp| u32::from(bp.max_geodes(32)))
|
||||||
.product();
|
.product();
|
||||||
|
|
||||||
Ok(result.to_string())
|
Ok(result.to_string())
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ fn shuffle(encrypted: &[i64], times: usize) -> Result<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn part2(input: &[u8]) -> Result<String> {
|
pub fn part2(input: &[u8]) -> Result<String> {
|
||||||
const ENCRYPTION_KEY: i64 = 811589153;
|
const ENCRYPTION_KEY: i64 = 811_589_153;
|
||||||
|
|
||||||
let mut encrypted = parse_input(input, parse_encrypted)?;
|
let mut encrypted = parse_input(input, parse_encrypted)?;
|
||||||
|
|
||||||
|
|||||||
@@ -81,13 +81,12 @@ pub fn part1(input: &[u8]) -> Result<String> {
|
|||||||
Step::Forward(amount) => match dir {
|
Step::Forward(amount) => match dir {
|
||||||
Direction::Up => {
|
Direction::Up => {
|
||||||
for _ in 0..amount {
|
for _ in 0..amount {
|
||||||
if y == 0 || map[y - 1].get(x).map(|&b| b == b' ').unwrap_or(true) {
|
if y == 0 || map[y - 1].get(x).map_or(true, |&b| b == b' ') {
|
||||||
let new_y = map
|
let new_y = map
|
||||||
.iter()
|
.iter()
|
||||||
.rposition(|line| {
|
.rposition(|line| {
|
||||||
line.get(x)
|
line.get(x)
|
||||||
.map(|&b| b == b'.' || b == b'#')
|
.map_or(false, |&b| b == b'.' || b == b'#')
|
||||||
.unwrap_or(false)
|
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
if map[new_y][x] == b'#' {
|
if map[new_y][x] == b'#' {
|
||||||
@@ -105,14 +104,13 @@ pub fn part1(input: &[u8]) -> Result<String> {
|
|||||||
Direction::Down => {
|
Direction::Down => {
|
||||||
for _ in 0..amount {
|
for _ in 0..amount {
|
||||||
if y + 1 >= map.len()
|
if y + 1 >= map.len()
|
||||||
|| map[y + 1].get(x).map(|&b| b == b' ').unwrap_or(true)
|
|| map[y + 1].get(x).map_or(true, |&b| b == b' ')
|
||||||
{
|
{
|
||||||
let new_y = map
|
let new_y = map
|
||||||
.iter()
|
.iter()
|
||||||
.position(|line| {
|
.position(|line| {
|
||||||
line.get(x)
|
line.get(x)
|
||||||
.map(|&b| b == b'.' || b == b'#')
|
.map_or(false, |&b| b == b'.' || b == b'#')
|
||||||
.unwrap_or(false)
|
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user