Skip to content

Commit

Permalink
Bump Rust version to 1.84
Browse files Browse the repository at this point in the history
  • Loading branch information
maneatingape committed Jan 9, 2025
1 parent bf8c14a commit 58bfd5a
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup default 1.83
- run: rustup default 1.84
- run: cargo test

test-nightly:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4
- run: rustup default 1.84
- run: cargo doc
env:
RUSTDOCFLAGS: "--document-private-items --default-theme=ayu --deny warnings"
Expand Down
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "aoc"
version = "2024.12.25"
edition = "2021"
rust-version = "1.83"
rust-version = "1.84"

[features]
frivolity = []
Expand Down Expand Up @@ -54,6 +54,7 @@ absolute_paths = "warn"
alloc_instead_of_core = "warn"
allow_attributes = "allow"
allow_attributes_without_reason = "allow"
arbitrary_source_item_ordering = "allow"
arithmetic_side_effects = "allow"
as_conversions = "allow"
as_underscore = "warn"
Expand Down Expand Up @@ -151,13 +152,15 @@ macro_use_imports = "warn"
manual_assert = "warn"
manual_c_str_literals = "warn"
manual_instant_elapsed = "warn"
manual_is_power_of_two = "warn"
manual_is_variant_and = "warn"
manual_let_else = "warn"
manual_ok_or = "warn"
manual_string_new = "warn"
many_single_char_names = "allow"
map_err_ignore = "warn"
map_unwrap_or = "warn"
map_with_unused_argument_over_ranges = "warn"
match_bool = "warn"
match_on_vec_items = "allow"
match_same_arms = "warn"
Expand Down Expand Up @@ -267,6 +270,7 @@ unimplemented = "warn"
uninlined_format_args = "warn"
unnecessary_box_returns = "warn"
unnecessary_join = "warn"
unnecessary_literal_bound = "warn"
unnecessary_safety_comment = "warn"
unnecessary_safety_doc = "warn"
unnecessary_self_imports = "warn"
Expand All @@ -284,7 +288,7 @@ unused_trait_names = "warn"
unwrap_in_result = "allow"
unwrap_used = "allow"
use_debug = "warn"
used_underscore_binding = "warn"
used_underscore_items = "warn"
verbose_bit_mask = "warn"
verbose_file_reads = "warn"
wildcard_enum_match_arm = "allow"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ Performance is reasonable even on older hardware, for example a 2011 MacBook Pro
| 19 | [Go With The Flow](https://adventofcode.com/2018/day/19) | [Source](src/year2018/day19.rs) | 1 |
| 20 | [A Regular Map](https://adventofcode.com/2018/day/20) | [Source](src/year2018/day20.rs) | 36 |
| 21 | [Chronal Conversion](https://adventofcode.com/2018/day/21) | [Source](src/year2018/day21.rs) | 66 |
| 22 | [Mode Maze](https://adventofcode.com/2018/day/22) | [Source](src/year2018/day22.rs) | 3396 |
| 22 | [Mode Maze](https://adventofcode.com/2018/day/22) | [Source](src/year2018/day22.rs) | 3197 |
| 23 | [Experimental Emergency Teleportation](https://adventofcode.com/2018/day/23) | [Source](src/year2018/day23.rs) | 506 |
| 24 | [Immune System Simulator 20XX](https://adventofcode.com/2018/day/24) | [Source](src/year2018/day24.rs) | 2056 |
| 25 | [Four-Dimensional Adventure](https://adventofcode.com/2018/day/25) | [Source](src/year2018/day25.rs) | 323 |
Expand Down Expand Up @@ -316,7 +316,7 @@ Performance is reasonable even on older hardware, for example a 2011 MacBook Pro
| 20 | [Particle Swarm](https://adventofcode.com/2017/day/20) | [Source](src/year2017/day20.rs) | 245 |
| 21 | [Fractal Art](https://adventofcode.com/2017/day/21) | [Source](src/year2017/day21.rs) | 5 |
| 22 | [Sporifica Virus](https://adventofcode.com/2017/day/22) | [Source](src/year2017/day22.rs) | 36000 |
| 23 | [Coprocessor Conflagration](https://adventofcode.com/2017/day/23) | [Source](src/year2017/day23.rs) | 55 |
| 23 | [Coprocessor Conflagration](https://adventofcode.com/2017/day/23) | [Source](src/year2017/day23.rs) | 54 |
| 24 | [Electromagnetic Moat](https://adventofcode.com/2017/day/24) | [Source](src/year2017/day24.rs) | 275 |
| 25 | [The Halting Problem](https://adventofcode.com/2017/day/25) | [Source](src/year2017/day25.rs) | 3698 |

Expand Down
7 changes: 0 additions & 7 deletions src/util/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub trait Integer<T>:
const ONE: T;
const TEN: T;

fn ilog2(self) -> T;
fn trailing_zeros(self) -> T;
}

Expand All @@ -37,12 +36,6 @@ macro_rules! integer {
const ONE: $t = 1;
const TEN: $t = 10;

#[inline]
#[allow(trivial_numeric_casts)]
fn ilog2(self) -> $t {
<$t>::ilog2(self) as $t
}

#[inline]
#[allow(trivial_numeric_casts)]
fn trailing_zeros(self) -> $t {
Expand Down
22 changes: 0 additions & 22 deletions src/util/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ pub trait IntegerMathOps<T: Integer<T>> {
fn mod_pow(self, e: T, m: T) -> T;
}

pub trait UnsignedMathOps<T: Unsigned<T>> {
fn sqrt(self) -> T;
}

pub trait SignedMathOps<T: Signed<T>> {
fn mod_inv(self, m: T) -> Option<T>;
}
Expand Down Expand Up @@ -64,24 +60,6 @@ impl<T: Integer<T>> IntegerMathOps<T> for T {
}
}

impl<T: Unsigned<T>> UnsignedMathOps<T> for T {
// Integer square root. Once [`isqrt`] is stablized then this function can be removed.
fn sqrt(self) -> T {
let mut bit = T::ONE << (self.ilog2() >> T::ONE);
let mut root = bit;

while bit > T::ONE {
bit = bit >> T::ONE;
let next = root | bit;
if next * next <= self {
root = next;
}
}

root
}
}

impl<T: Signed<T>> SignedMathOps<T> for T {
// Modular multiplicative inverse
fn mod_inv(self, m: T) -> Option<T> {
Expand Down
4 changes: 1 addition & 3 deletions src/year2017/day23.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
//! this directly would take at least 10⁵.10⁵.10³ = 10¹³ = 10,000,000,000,000 steps.
//!
//! [`Day 18`]: crate::year2017::day18
use crate::util::math::*;
use crate::util::parse::*;

/// We only need the vrey first number from the input.
Expand All @@ -71,7 +69,7 @@ pub fn part2(input: &u32) -> usize {
/// Simple [prime number check](https://en.wikipedia.org/wiki/Primality_test)
/// of all factors from 2 to √n inclusive.
fn composite(n: u32) -> Option<u32> {
for f in 2..=n.sqrt() {
for f in 2..=n.isqrt() {
if n % f == 0 {
return Some(n);
}
Expand Down
3 changes: 2 additions & 1 deletion src/year2018/day22.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::util::grid::*;
use crate::util::iter::*;
use crate::util::parse::*;
use crate::util::point::*;
use std::iter::repeat_with;

/// The index of each tool is that tool that *cannot* be used in that region, for example
/// Rocky => 0 => Neither, Wet => 1 => Torch and Narrow => 2 => Climbing Gear.
Expand Down Expand Up @@ -72,7 +73,7 @@ pub fn part2(input: &Input) -> i32 {

// Initialise bucket queue with pre-allocated capacity to reduce reallocations needed.
let mut base = 0;
let mut todo = (0..BUCKETS).map(|_| Vec::with_capacity(1000)).collect::<Vec<_>>();
let mut todo = repeat_with(|| Vec::with_capacity(1000)).take(BUCKETS).collect::<Vec<_>>();

// Add extra width and height so the search does not exceed the bounds of the grid.
let mut cave = scan_cave(input, width + 10, height + 140);
Expand Down
19 changes: 10 additions & 9 deletions src/year2019/day14.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::util::hash::*;
use crate::util::iter::*;
use crate::util::parse::*;
use std::cmp::Ordering;
use std::iter::repeat_with;

struct Ingredient {
amount: u64,
Expand All @@ -23,15 +24,15 @@ pub struct Reaction {
pub fn parse(input: &str) -> Vec<Reaction> {
let lines: Vec<_> = input.lines().collect();

let mut reactions: Vec<_> = (0..lines.len() + 1)
.map(|_| {
Reaction {
amount: 0,
chemical: 1, // Default to ORE, other chemicals will overwrite.
ingredients: Vec::new(),
}
})
.collect();
let mut reactions: Vec<_> = repeat_with(|| {
Reaction {
amount: 0,
chemical: 1, // Default to ORE, other chemicals will overwrite.
ingredients: Vec::new(),
}
})
.take(lines.len() + 1)
.collect();

// Assign FUEL and ORE known indices as we'll need to look them up later.
let mut indices = FastMap::new();
Expand Down
3 changes: 1 addition & 2 deletions src/year2023/day06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
//! [quadratic formula](https://en.wikipedia.org/wiki/Quadratic_formula).
//!
//! * `(t ± √(t² - 4d)) / 2`
use crate::util::math::*;
use crate::util::parse::*;

pub fn parse(input: &str) -> Vec<&str> {
Expand All @@ -45,7 +44,7 @@ fn race(first: &str, second: &str) -> u128 {

for (time, distance) in times.zip(distances) {
// Use the quadratic formula to find the start and end positions.
let root = (time * time - 4 * distance).sqrt();
let root = (time * time - 4 * distance).isqrt();
let mut start = (time - root).div_ceil(2);
let mut end = (time + root) / 2;

Expand Down
3 changes: 2 additions & 1 deletion src/year2023/day15.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//!
//! Calculates part one and two at the same time as a speed optimization.
use crate::util::parse::*;
use std::iter::repeat_with;

type Input = (usize, usize);

Expand All @@ -13,7 +14,7 @@ struct Item<'a> {
pub fn parse(input: &str) -> Input {
let mut part_one = 0;
let mut part_two = 0;
let mut boxes: Vec<Vec<Item<'_>>> = (0..256).map(|_| Vec::new()).collect();
let mut boxes: Vec<Vec<Item<'_>>> = repeat_with(Vec::new).take(256).collect();

for step in input.trim().as_bytes().split(|&b| b == b',') {
let size = step.len();
Expand Down
3 changes: 2 additions & 1 deletion src/year2023/day17.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
//! [`BinaryHeap`]: std::collections::BinaryHeap
use crate::util::grid::*;
use crate::util::parse::*;
use std::iter::repeat_with;

/// Parse the input into a 2D grid of `u8` then convert to `u32` for convenience.
pub fn parse(input: &str) -> Grid<i32> {
Expand Down Expand Up @@ -55,7 +56,7 @@ fn astar<const L: i32, const U: i32>(grid: &Grid<i32>) -> i32 {
let heat = &grid.bytes;

let mut index = 0;
let mut todo = (0..100).map(|_| Vec::with_capacity(1000)).collect::<Vec<_>>();
let mut todo = repeat_with(|| Vec::with_capacity(1000)).take(100).collect::<Vec<_>>();
let mut cost = vec![[i32::MAX; 2]; heat.len()];

// Start from the top left corner checking both vertical and horizontal directions.
Expand Down
3 changes: 2 additions & 1 deletion src/year2024/day09.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//! When moving a file to a free block, the corresponding heap is popped and then any leftover
//! space is pushed back to the heap at a smaller index. The heap at index zero is not used
//! but makes the indexing easier.
use std::iter::repeat_with;

/// [Triangular numbers](https://en.wikipedia.org/wiki/Triangular_number) offset by two.
/// Files can be a max size of 9 so we only need the first 10 values, including zero to make
Expand Down Expand Up @@ -66,7 +67,7 @@ pub fn part1(disk: &[usize]) -> usize {
pub fn part2(disk: &[usize]) -> usize {
let mut block = 0;
let mut checksum = 0;
let mut free: Vec<_> = (0..10).map(|_| Vec::with_capacity(1_100)).collect();
let mut free: Vec<_> = repeat_with(|| Vec::with_capacity(1_100)).take(10).collect();

// Build a min-heap (leftmost free block first) where the size of each block is
// implicit in the index of the array.
Expand Down

0 comments on commit 58bfd5a

Please sign in to comment.