Skip to content

Commit

Permalink
Merge pull request #351 from paulcacheux/bump-toolchain-2024
Browse files Browse the repository at this point in the history
Bump toolchain 2024
  • Loading branch information
paulcacheux authored Dec 8, 2024
2 parents 6b21e80 + e8888ce commit be01c92
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 112 deletions.
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-12-17"
channel = "nightly-2024-11-26"
components = [ "rustfmt", "clippy" ]
2 changes: 1 addition & 1 deletion src/aoc2021/day3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub struct MaskedBits<'b> {
pub line_mask: Vec<bool>,
}

impl<'b> Deref for MaskedBits<'b> {
impl Deref for MaskedBits<'_> {
type Target = OptimizedBits;

fn deref(&self) -> &OptimizedBits {
Expand Down
2 changes: 1 addition & 1 deletion src/aoc2022/day17.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn dbg_state(state: &Vec<Vec<bool>>) {

#[inline]
fn solve(input: &[i32], steps: usize) -> usize {
let blocks = vec![
let blocks = [
vec![
[true, false, false, false],
[true, false, false, false],
Expand Down
43 changes: 23 additions & 20 deletions src/aoc2022/day18.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,29 @@ fn neighbors(
z: usize,
width: usize,
) -> impl Iterator<Item = (usize, usize, usize)> {
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 {
Expand Down
59 changes: 31 additions & 28 deletions src/aoc2022/day19.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<STEPS>(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::<STEPS>(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;
}
}
},
)
}
}
98 changes: 52 additions & 46 deletions src/aoc2023/day3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,63 +36,69 @@ impl Entry {
&'a self,
grid: &'b Grid<u8>,
) -> impl Iterator<Item = (usize, usize)> + '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<u8>) -> impl Iterator<Item = Entry> + '_ {
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)]
Expand Down
31 changes: 17 additions & 14 deletions src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,23 @@ impl<T> Grid<T> {
) -> impl Iterator<Item = (Direction, usize, usize)> {
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);
}
},
)
}
}

Expand Down
1 change: 1 addition & 0 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ macro_rules! inner_run {
}

pub struct TimingData {
#[allow(dead_code)]
pub parsing: Duration,
pub part1: Duration,
pub part2: Duration,
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#![feature(get_many_mut)]
#![feature(coroutines)]
#![feature(iter_from_coroutine)]
#![feature(is_sorted)]

use std::time::Duration;

Expand Down

0 comments on commit be01c92

Please sign in to comment.