Skip to content

Commit

Permalink
Update dependencies and disable aoc_generators for Advent of Code 2023
Browse files Browse the repository at this point in the history
Signed-off-by: Andrej Orsula <orsula.andrej@gmail.com>
  • Loading branch information
AndrejOrsula committed Nov 30, 2024
1 parent 73b59e4 commit d29defd
Show file tree
Hide file tree
Showing 30 changed files with 293 additions and 247 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ concurrency:
cancel-in-progress: true

env:
MSRV: "1.74"
MSRV: "1.75"
CARGO_TERM_COLOR: always

jobs:
Expand Down
9 changes: 2 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,17 @@ repos:
- id: beautysh

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.3.0
hooks:
- id: codespell
args: ["--ignore-words-list", "crate"]
exclude: Cargo.lock|input/.*|aoc2023/.*/day15.rs

- repo: https://github.com/hadolint/hadolint
rev: v2.12.1-beta
rev: v2.13.1-beta
hooks:
- id: hadolint-docker

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
- id: mdformat

- repo: https://github.com/AndrejOrsula/pre-commit-cargo
rev: 0.3.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG RUST_VERSION=1.74
ARG RUST_VERSION=latest
FROM rust:${RUST_VERSION}

### Use bash as the default shell
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ My solutions to [Advent of Code](https://adventofcode.com) puzzles.

## Edition

### [Advent of Code 2023](https://adventofcode.com/2023)
<details><summary><h3><a href="https://adventofcode.com/2023">Advent of Code 2023</a></h3></summary>

> All benchmarks are run on a *Dell Precision 5550* laptop with an *Intel Core i7-10875H* CPU.
Expand Down Expand Up @@ -105,10 +105,11 @@ My solutions to [Advent of Code](https://adventofcode.com) puzzles.
| 252.4 µs | 61.18 ms |
| 101.2 µs | 2.5839 s |
| 79.73 µs | 2.4001 s |
| 0.000 µs | 0.000 µs |
| | |

</td></tr>
</table>
</details>

## Instructions

Expand Down
7 changes: 4 additions & 3 deletions aoc2023/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
name = "aoc2023"
description = "Advent of Code 2023"
edition = "2021"
rust-version = "1.74"
rust-version = "1.75"
version = "0.1.0"
authors.workspace = true
keywords.workspace = true
license.workspace = true
readme.workspace = true
repository.workspace = true
publish = false

[dependencies]
aoc-runner = { workspace = true }
aoc-runner-derive = { workspace = true }
indoc = { workspace = true }

derive_more = { version = "0.99" }
itertools = { version = "0.12" }
derive_more = { version = "1", features = ["full"] }
itertools = { version = "0.13" }
num = { version = "0.4" }
num-integer = { version = "0.1" }
pathfinding = { version = "4.4" }
Expand Down
21 changes: 9 additions & 12 deletions aoc2023/src/day1.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use aoc_runner_derive::{aoc, aoc_generator};

#[aoc_generator(day1)]
fn parse(input: &str) -> String {
input.to_owned()
}
use aoc_runner_derive::aoc;

#[aoc(day1, part1)]
fn part1(input: &str) -> u32 {
#[must_use]
pub fn part1(input: &str) -> u32 {
input
.lines()
.map(|line| {
Expand All @@ -20,7 +16,8 @@ fn part1(input: &str) -> u32 {
}

#[aoc(day1, part2)]
fn part2(input: &str) -> u32 {
#[must_use]
pub fn part2(input: &str) -> u32 {
input
.lines()
.map(|line| {
Expand Down Expand Up @@ -149,18 +146,18 @@ mod tests {
use indoc::indoc;

#[test]
fn part1_example() {
pub fn part1_example() {
const SAMPLE: &str = indoc! {"
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet
"};
assert_eq!(part1(&parse(SAMPLE)), 142);
assert_eq!(part1(SAMPLE), 142);
}

#[test]
fn part2_example() {
pub fn part2_example() {
const SAMPLE: &str = indoc! {"
two1nine
eightwothree
Expand All @@ -170,6 +167,6 @@ mod tests {
zoneight234
7pqrstsixteen
"};
assert_eq!(part2(&parse(SAMPLE)), 281);
assert_eq!(part2(SAMPLE), 281);
}
}
25 changes: 14 additions & 11 deletions aoc2023/src/day10.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use aoc_runner_derive::{aoc, aoc_generator};
use aoc_runner_derive::aoc;

#[aoc_generator(day10)]
fn parse(input: &str) -> utils::Map {
let mut grid = pathfinding::matrix::Matrix::new(
input.lines().count(),
Expand All @@ -25,13 +24,17 @@ fn parse(input: &str) -> utils::Map {
}

#[aoc(day10, part1)]
fn part1(input: &utils::Map) -> usize {
#[must_use]
pub fn part1(input: &str) -> usize {
let input = parse(input);
// The furthest point from the start is always the middle of the loop
input.get_loop().len() / 2
}

#[aoc(day10, part2)]
fn part2(input: &utils::Map) -> usize {
#[must_use]
pub fn part2(input: &str) -> usize {
let input = parse(input);
// Construct a grid that only contains the loop
let mut enclosure =
pathfinding::matrix::Matrix::new(input.grid.rows, input.grid.columns, utils::Tile::Ground);
Expand Down Expand Up @@ -174,7 +177,7 @@ mod tests {
use indoc::indoc;

#[test]
fn part1_example() {
pub fn part1_example() {
const SAMPLES: [&str; 2] = [
indoc! {"
.....
Expand All @@ -192,12 +195,12 @@ mod tests {
"},
];

assert_eq!(part1(&parse(SAMPLES[0])), 4);
assert_eq!(part1(&parse(SAMPLES[1])), 8);
assert_eq!(part1(SAMPLES[0]), 4);
assert_eq!(part1(SAMPLES[1]), 8);
}

#[test]
fn part2_example() {
pub fn part2_example() {
const SAMPLES: [&str; 3] = [
indoc! {"
...........
Expand Down Expand Up @@ -236,8 +239,8 @@ mod tests {
"},
];

assert_eq!(part2(&parse(SAMPLES[0])), 4);
assert_eq!(part2(&parse(SAMPLES[1])), 8);
assert_eq!(part2(&parse(SAMPLES[2])), 10);
assert_eq!(part2(SAMPLES[0]), 4);
assert_eq!(part2(SAMPLES[1]), 8);
assert_eq!(part2(SAMPLES[2]), 10);
}
}
32 changes: 20 additions & 12 deletions aoc2023/src/day11.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
use aoc_runner_derive::{aoc, aoc_generator};
use aoc_runner_derive::aoc;

#[aoc_generator(day11, part1)]
fn parse1(input: &str) -> Vec<(usize, usize)> {
utils::parse_expanded_galaxies(input, 1)
}

#[aoc_generator(day11, part2)]
fn parse2(input: &str) -> Vec<(usize, usize)> {
utils::parse_expanded_galaxies(input, 999_999)
}

#[aoc(day11, part1)]
fn part1(input: &[(usize, usize)]) -> usize {
utils::sum_galactic_distances(input)
#[must_use]
pub fn part1(input: &str) -> usize {
let input = parse1(input);
utils::sum_galactic_distances(&input)
}

#[aoc(day11, part2)]
fn part2(input: &[(usize, usize)]) -> usize {
utils::sum_galactic_distances(input)
#[must_use]
pub fn part2(input: &str) -> usize {
let input = parse2(input);
utils::sum_galactic_distances(&input)
}

mod utils {
Expand Down Expand Up @@ -133,13 +135,19 @@ mod tests {
"};

#[test]
fn part1_example() {
assert_eq!(part1(&parse1(SAMPLE)), 374);
pub fn part1_example() {
assert_eq!(part1(SAMPLE), 374);
}

#[test]
fn part2_example() {
assert_eq!(part2(&utils::parse_expanded_galaxies(SAMPLE, 9)), 1030);
assert_eq!(part2(&utils::parse_expanded_galaxies(SAMPLE, 99)), 8410);
pub fn part2_example() {
assert_eq!(
utils::sum_galactic_distances(&utils::parse_expanded_galaxies(SAMPLE, 9)),
1030
);
assert_eq!(
utils::sum_galactic_distances(&utils::parse_expanded_galaxies(SAMPLE, 99)),
8410
);
}
}
18 changes: 10 additions & 8 deletions aoc2023/src/day12.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use aoc_runner_derive::{aoc, aoc_generator};
use aoc_runner_derive::aoc;

#[aoc_generator(day12)]
fn parse(input: &str) -> Vec<utils::SpringSequence> {
input
.lines()
Expand All @@ -19,15 +18,18 @@ fn parse(input: &str) -> Vec<utils::SpringSequence> {
}

#[aoc(day12, part1)]
fn part1(input: &[utils::SpringSequence]) -> usize {
pub fn part1(input: &str) -> usize {
let input = parse(input);
input
.iter()
.map(utils::SpringSequence::discover_arrangements)
.sum()
}

#[aoc(day12, part2)]
fn part2(input: &[utils::SpringSequence]) -> usize {
#[must_use]
pub fn part2(input: &str) -> usize {
let input = parse(input);
input
.iter()
.map(|sequence| {
Expand Down Expand Up @@ -155,12 +157,12 @@ mod tests {
"};

#[test]
fn part1_example() {
assert_eq!(part1(&parse(SAMPLE)), 21);
pub fn part1_example() {
assert_eq!(part1(SAMPLE), 21);
}

#[test]
fn part2_example() {
assert_eq!(part2(&parse(SAMPLE)), 525_152);
pub fn part2_example() {
assert_eq!(part2(SAMPLE), 525_152);
}
}
19 changes: 11 additions & 8 deletions aoc2023/src/day13.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use aoc_runner_derive::{aoc, aoc_generator};
use aoc_runner_derive::aoc;

#[aoc_generator(day13)]
fn parse(input: &str) -> Vec<utils::Pattern> {
input
.split("\n\n")
Expand All @@ -9,7 +8,9 @@ fn parse(input: &str) -> Vec<utils::Pattern> {
}

#[aoc(day13, part1)]
fn part1(input: &[utils::Pattern]) -> usize {
#[must_use]
pub fn part1(input: &str) -> usize {
let input = parse(input);
input
.iter()
.map(|pattern| {
Expand All @@ -19,9 +20,11 @@ fn part1(input: &[utils::Pattern]) -> usize {
}

#[aoc(day13, part2)]
fn part2(input: &[utils::Pattern]) -> usize {
#[must_use]
pub fn part2(input: &str) -> usize {
use rayon::prelude::*;

let input = parse(input);
input
.iter()
.par_bridge()
Expand Down Expand Up @@ -99,12 +102,12 @@ mod tests {
"};

#[test]
fn part1_example() {
assert_eq!(part1(&parse(SAMPLE)), 405);
pub fn part1_example() {
assert_eq!(part1(SAMPLE), 405);
}

#[test]
fn part2_example() {
assert_eq!(part2(&parse(SAMPLE)), 400);
pub fn part2_example() {
assert_eq!(part2(SAMPLE), 400);
}
}
Loading

0 comments on commit d29defd

Please sign in to comment.