From 49392e3ed467f37bece708f644d53dcddd9f97a7 Mon Sep 17 00:00:00 2001 From: Paul Cacheux Date: Sun, 8 Dec 2024 14:23:34 +0100 Subject: [PATCH 1/5] bump nightly version --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" ] From 00fb7a8ce908c53ec04977acfbe4b1f7a9d94b84 Mon Sep 17 00:00:00 2001 From: Paul Cacheux Date: Sun, 8 Dec 2024 14:24:40 +0100 Subject: [PATCH 2/5] remove stable feature --- src/main.rs | 1 - 1 file changed, 1 deletion(-) 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; From 60c838929a35c4c834a088c9eecf68384318ed13 Mon Sep 17 00:00:00 2001 From: Paul Cacheux Date: Sun, 8 Dec 2024 14:29:33 +0100 Subject: [PATCH 3/5] fix a few coroutines missing --- src/aoc2022/day18.rs | 2 +- src/aoc2022/day19.rs | 2 +- src/aoc2023/day3.rs | 4 ++-- src/grid.rs | 2 +- src/helpers.rs | 1 + 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/aoc2022/day18.rs b/src/aoc2022/day18.rs index 4489db1..af8fb8a 100644 --- a/src/aoc2022/day18.rs +++ b/src/aoc2022/day18.rs @@ -83,7 +83,7 @@ fn neighbors( z: usize, width: usize, ) -> impl Iterator { - std::iter::from_coroutine(move || { + std::iter::from_coroutine(#[coroutine] move || { if x > 0 { yield (x - 1, y, z); } diff --git a/src/aoc2022/day19.rs b/src/aoc2022/day19.rs index d53f336..38ea597 100644 --- a/src/aoc2022/day19.rs +++ b/src/aoc2022/day19.rs @@ -234,7 +234,7 @@ impl State { let min_use = bp.min_use; let max_use = bp.max_use; - std::iter::from_coroutine(move || { + std::iter::from_coroutine(#[coroutine] move || { // not buying let mut ns = self; ns.collect(); diff --git a/src/aoc2023/day3.rs b/src/aoc2023/day3.rs index f254c58..984e17b 100644 --- a/src/aoc2023/day3.rs +++ b/src/aoc2023/day3.rs @@ -36,7 +36,7 @@ impl Entry { &'a self, grid: &'b Grid, ) -> impl Iterator + 'b { - std::iter::from_coroutine(move || { + std::iter::from_coroutine(#[coroutine] move || { let x = self.x as i32; let y = self.y as i32; let len = self.len as i32; @@ -61,7 +61,7 @@ impl Entry { #[inline] fn get_entries(input: &Grid) -> impl Iterator + '_ { - std::iter::from_coroutine(move || { + std::iter::from_coroutine(#[coroutine] move || { let mut current = None; for y in 0..input.height { for x in 0..input.width { diff --git a/src/grid.rs b/src/grid.rs index a9a3ea2..c200630 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -73,7 +73,7 @@ impl Grid { ) -> impl Iterator { let width = self.width; let height = self.height; - std::iter::from_coroutine(move || { + std::iter::from_coroutine(#[coroutine] move || { if x != 0 { yield (Direction::West, x - 1, y); } 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, From 647bac9bc45e806aeadc45e7886cef8ebafc7083 Mon Sep 17 00:00:00 2001 From: Paul Cacheux Date: Sun, 8 Dec 2024 14:31:20 +0100 Subject: [PATCH 4/5] format code --- src/aoc2022/day18.rs | 43 ++++++++++--------- src/aoc2022/day19.rs | 59 +++++++++++++------------- src/aoc2023/day3.rs | 98 +++++++++++++++++++++++--------------------- src/grid.rs | 31 +++++++------- 4 files changed, 123 insertions(+), 108 deletions(-) diff --git a/src/aoc2022/day18.rs b/src/aoc2022/day18.rs index af8fb8a..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(#[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 38ea597..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(#[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 984e17b..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(#[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(#[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 c200630..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(#[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); + } + }, + ) } } From e8888ceac6591b40bc46ca00621934e12e1e16cd Mon Sep 17 00:00:00 2001 From: Paul Cacheux Date: Sun, 8 Dec 2024 14:33:04 +0100 Subject: [PATCH 5/5] fix clippy warnings --- src/aoc2021/day3.rs | 2 +- src/aoc2022/day17.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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],