diff --git a/rust-toolchain.toml b/rust-toolchain.toml index dd64ec1..6b0f839 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-12-17" +channel = "nightly-2024-11-26" components = [ "rustfmt", "clippy" ] diff --git a/src/aoc2021/day3.rs b/src/aoc2021/day3.rs index dcc874a..dff767d 100644 --- a/src/aoc2021/day3.rs +++ b/src/aoc2021/day3.rs @@ -94,7 +94,7 @@ pub struct MaskedBits<'b> { pub line_mask: Vec, } -impl<'b> Deref for MaskedBits<'b> { +impl Deref for MaskedBits<'_> { type Target = OptimizedBits; fn deref(&self) -> &OptimizedBits { diff --git a/src/aoc2022/day17.rs b/src/aoc2022/day17.rs index c171596..84b74c6 100644 --- a/src/aoc2022/day17.rs +++ b/src/aoc2022/day17.rs @@ -85,7 +85,7 @@ fn dbg_state(state: &Vec>) { #[inline] fn solve(input: &[i32], steps: usize) -> usize { - let blocks = vec![ + let blocks = [ vec![ [true, false, false, false], [true, false, false, false], diff --git a/src/aoc2022/day18.rs b/src/aoc2022/day18.rs index 4489db1..983e0a5 100644 --- a/src/aoc2022/day18.rs +++ b/src/aoc2022/day18.rs @@ -83,26 +83,29 @@ fn neighbors( z: usize, width: usize, ) -> impl Iterator { - std::iter::from_coroutine(move || { - if x > 0 { - yield (x - 1, y, z); - } - if x + 1 < width { - yield (x + 1, y, z); - } - if y > 0 { - yield (x, y - 1, z); - } - if y + 1 < width { - yield (x, y + 1, z); - } - if z > 0 { - yield (x, y, z - 1); - } - if z + 1 < width { - yield (x, y, z + 1); - } - }) + std::iter::from_coroutine( + #[coroutine] + move || { + if x > 0 { + yield (x - 1, y, z); + } + if x + 1 < width { + yield (x + 1, y, z); + } + if y > 0 { + yield (x, y - 1, z); + } + if y + 1 < width { + yield (x, y + 1, z); + } + if z > 0 { + yield (x, y, z - 1); + } + if z + 1 < width { + yield (x, y, z + 1); + } + }, + ) } struct Cube3D { diff --git a/src/aoc2022/day19.rs b/src/aoc2022/day19.rs index d53f336..4562cb3 100644 --- a/src/aoc2022/day19.rs +++ b/src/aoc2022/day19.rs @@ -234,37 +234,40 @@ impl State { let min_use = bp.min_use; let max_use = bp.max_use; - std::iter::from_coroutine(move || { - // not buying - let mut ns = self; - ns.collect(); - ns.move_ahead::(min_use); - yield ns; - - // buying - if let Some(mut next) = self.can_buy(geode_bot) { - // directly add all geodes instead of creating a robot - next.key.geode += (STEPS - ns.step) as u16; - yield next; - } - if self.key.bot.obsidian < max_use.obsidian { - if let Some(mut next) = self.can_buy(obs_bot) { - next.key.bot.obsidian += 1; + std::iter::from_coroutine( + #[coroutine] + move || { + // not buying + let mut ns = self; + ns.collect(); + ns.move_ahead::(min_use); + yield ns; + + // buying + if let Some(mut next) = self.can_buy(geode_bot) { + // directly add all geodes instead of creating a robot + next.key.geode += (STEPS - ns.step) as u16; yield next; } - } - if self.key.bot.clay < max_use.clay { - if let Some(mut next) = self.can_buy(clay_bot) { - next.key.bot.clay += 1; - yield next; + if self.key.bot.obsidian < max_use.obsidian { + if let Some(mut next) = self.can_buy(obs_bot) { + next.key.bot.obsidian += 1; + yield next; + } } - } - if self.key.bot.ore < max_use.ore { - if let Some(mut next) = self.can_buy(ore_bot) { - next.key.bot.ore += 1; - yield next; + if self.key.bot.clay < max_use.clay { + if let Some(mut next) = self.can_buy(clay_bot) { + next.key.bot.clay += 1; + yield next; + } } - } - }) + if self.key.bot.ore < max_use.ore { + if let Some(mut next) = self.can_buy(ore_bot) { + next.key.bot.ore += 1; + yield next; + } + } + }, + ) } } diff --git a/src/aoc2023/day3.rs b/src/aoc2023/day3.rs index f254c58..a37d052 100644 --- a/src/aoc2023/day3.rs +++ b/src/aoc2023/day3.rs @@ -36,63 +36,69 @@ impl Entry { &'a self, grid: &'b Grid, ) -> impl Iterator + 'b { - std::iter::from_coroutine(move || { - let x = self.x as i32; - let y = self.y as i32; - let len = self.len as i32; - - maybe_yield!(grid, x - 1, y - 1); - for dx in 0..len { - maybe_yield!(grid, x + dx, y - 1); - } - maybe_yield!(grid, x + len, y - 1); + std::iter::from_coroutine( + #[coroutine] + move || { + let x = self.x as i32; + let y = self.y as i32; + let len = self.len as i32; + + maybe_yield!(grid, x - 1, y - 1); + for dx in 0..len { + maybe_yield!(grid, x + dx, y - 1); + } + maybe_yield!(grid, x + len, y - 1); - maybe_yield!(grid, x - 1, y); - maybe_yield!(grid, x + len, y); + maybe_yield!(grid, x - 1, y); + maybe_yield!(grid, x + len, y); - maybe_yield!(grid, x - 1, y + 1); - for dx in 0..len { - maybe_yield!(grid, x + dx, y + 1); - } - maybe_yield!(grid, x + len, y + 1); - }) + maybe_yield!(grid, x - 1, y + 1); + for dx in 0..len { + maybe_yield!(grid, x + dx, y + 1); + } + maybe_yield!(grid, x + len, y + 1); + }, + ) } } #[inline] fn get_entries(input: &Grid) -> impl Iterator + '_ { - std::iter::from_coroutine(move || { - let mut current = None; - for y in 0..input.height { - for x in 0..input.width { - let c = *input.get(x, y); - if c.is_ascii_digit() { - let digit = (c - b'0') as u32; - - current = match current { - Some(Entry { x, y, len, value }) => Some(Entry { - x, - y, - len: len + 1, - value: value * 10 + digit, - }), - None => Some(Entry { - x, - y, - len: 1, - value: digit, - }), + std::iter::from_coroutine( + #[coroutine] + move || { + let mut current = None; + for y in 0..input.height { + for x in 0..input.width { + let c = *input.get(x, y); + if c.is_ascii_digit() { + let digit = (c - b'0') as u32; + + current = match current { + Some(Entry { x, y, len, value }) => Some(Entry { + x, + y, + len: len + 1, + value: value * 10 + digit, + }), + None => Some(Entry { + x, + y, + len: 1, + value: digit, + }), + } + } else if let Some(entry) = current.take() { + yield entry; } - } else if let Some(entry) = current.take() { - yield entry; } } - } - if let Some(entry) = current { - yield entry; - } - }) + if let Some(entry) = current { + yield entry; + } + }, + ) } #[derive(Debug, Clone)] diff --git a/src/grid.rs b/src/grid.rs index a9a3ea2..5c5117d 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -73,20 +73,23 @@ impl Grid { ) -> impl Iterator { let width = self.width; let height = self.height; - std::iter::from_coroutine(move || { - if x != 0 { - yield (Direction::West, x - 1, y); - } - if y != 0 { - yield (Direction::North, x, y - 1); - } - if x != width - 1 { - yield (Direction::East, x + 1, y); - } - if y != height - 1 { - yield (Direction::South, x, y + 1); - } - }) + std::iter::from_coroutine( + #[coroutine] + move || { + if x != 0 { + yield (Direction::West, x - 1, y); + } + if y != 0 { + yield (Direction::North, x, y - 1); + } + if x != width - 1 { + yield (Direction::East, x + 1, y); + } + if y != height - 1 { + yield (Direction::South, x, y + 1); + } + }, + ) } } diff --git a/src/helpers.rs b/src/helpers.rs index c59c5dd..91d4823 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -76,6 +76,7 @@ macro_rules! inner_run { } pub struct TimingData { + #[allow(dead_code)] pub parsing: Duration, pub part1: Duration, pub part2: Duration, diff --git a/src/main.rs b/src/main.rs index 7afc803..9aebb26 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,6 @@ #![feature(get_many_mut)] #![feature(coroutines)] #![feature(iter_from_coroutine)] -#![feature(is_sorted)] use std::time::Duration;