Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ff8eaeb

Browse files
Bump Rust version to 1.86
1 parent 0e406ad commit ff8eaeb

File tree

5 files changed

+15
-18
lines changed

5 files changed

+15
-18
lines changed

‎.github/workflows/checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- uses: actions/checkout@v4
23-
- run: rustup default 1.85
23+
- run: rustup default 1.86
2424
- run: cargo test
2525

2626
test-nightly:

‎.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
url: ${{ steps.deployment.outputs.page_url }}
1919
steps:
2020
- uses: actions/checkout@v4
21-
- run: rustup default 1.85
21+
- run: rustup default 1.86
2222
- run: cargo doc
2323
env:
2424
RUSTDOCFLAGS: "--document-private-items --default-theme=ayu --deny warnings"

‎Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "aoc"
33
version = "2024年12月25日"
44
edition = "2024"
5-
rust-version = "1.85"
5+
rust-version = "1.86"
66

77
[features]
88
frivolity = []
@@ -199,6 +199,7 @@ needless_raw_strings = "warn"
199199
no_effect_underscore_binding = "warn"
200200
no_mangle_with_rust_abi = "warn"
201201
non_ascii_literal = "allow"
202+
non_std_lazy_statics = "warn"
202203
non_zero_suggestions = "warn"
203204
option_as_ref_cloned = "warn"
204205
option_option = "warn"
@@ -207,6 +208,7 @@ panic_in_result_fn = "warn"
207208
partial_pub_fields = "warn"
208209
pathbuf_init_then_push = "warn"
209210
pattern_type_mismatch = "allow"
211+
precedence_bits = "warn"
210212
print_stderr = "allow"
211213
print_stdout = "allow"
212214
ptr_as_ptr = "warn"
@@ -218,6 +220,7 @@ pub_without_shorthand = "warn"
218220
question_mark_used = "allow"
219221
range_minus_one = "warn"
220222
range_plus_one = "allow"
223+
return_and_then = "warn"
221224
rc_buffer = "warn"
222225
rc_mutex = "warn"
223226
redundant_closure_for_method_calls = "warn"
@@ -276,6 +279,7 @@ unnecessary_literal_bound = "warn"
276279
unnecessary_safety_comment = "warn"
277280
unnecessary_safety_doc = "warn"
278281
unnecessary_self_imports = "warn"
282+
unnecessary_semicolon = "warn"
279283
unnecessary_wraps = "warn"
280284
unneeded_field_pattern = "warn"
281285
unnested_or_patterns = "warn"

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Performance is reasonable even on older hardware, for example a 2011 MacBook Pro
138138
| 2 | [Rock Paper Scissors](https://adventofcode.com/2022/day/2) | [Source](src/year2022/day02.rs) | 3 |
139139
| 3 | [Rucksack Reorganization](https://adventofcode.com/2022/day/3) | [Source](src/year2022/day03.rs) | 13 |
140140
| 4 | [Camp Cleanup](https://adventofcode.com/2022/day/4) | [Source](src/year2022/day04.rs) | 8 |
141-
| 5 | [Supply Stacks](https://adventofcode.com/2022/day/5) | [Source](src/year2022/day05.rs) | 14 |
141+
| 5 | [Supply Stacks](https://adventofcode.com/2022/day/5) | [Source](src/year2022/day05.rs) | 13 |
142142
| 6 | [Tuning Trouble](https://adventofcode.com/2022/day/6) | [Source](src/year2022/day06.rs) | 3 |
143143
| 7 | [No Space Left On Device](https://adventofcode.com/2022/day/7) | [Source](src/year2022/day07.rs) | 14 |
144144
| 8 | [Treetop Tree House](https://adventofcode.com/2022/day/8) | [Source](src/year2022/day08.rs) | 51 |

‎src/year2022/day05.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
//! # Supply Stacks
2-
//!
3-
//! There are 2 main challenges to this problem:
4-
//! * Parsing the input!
5-
//! * (Rust Specific): The borrow checker prevents mutating a nested `vec` at 2 indices at once.
62
use crate::util::iter::*;
73
use crate::util::parse::*;
84

@@ -61,26 +57,23 @@ pub fn part2(input: &Input) -> String {
6157
play(input, false)
6258
}
6359

64-
/// Rust's borrow checker won't allow us to mutate 2 nested `vec`s simulataneously, so we need
65-
/// to use an temporary intermediate `vec` to store the moving crates. For efficiency we can re-use
66-
/// the same vec to prevent unnecessary memory allocations.
67-
///
60+
/// `get_disjoint_mut` allows us to acquire two simultaneous mutable references to disjoint indices.
6861
/// A nice standard library feature is that we can collect an iterator of `char`s into a `String`
6962
/// for the final answer.
7063
fn play(input: &Input, reverse: bool) -> String {
7164
let (initial, moves) = input;
7265
let mut stack = initial.clone();
73-
let mut crates = Vec::new();
7466

7567
for &[amount, from, to] in moves {
76-
let start = stack[from].len() - amount;
77-
crates.extend(stack[from].drain(start..));
68+
let [from, to] = stack.get_disjoint_mut([from, to]).unwrap();
69+
let start = from.len() - amount;
70+
let iter = from.drain(start..);
71+
7872
if reverse {
79-
stack[to].extend(crates.iter().rev());
73+
to.extend(iter.rev());
8074
} else {
81-
stack[to].extend(crates.iter());
75+
to.extend(iter);
8276
}
83-
crates.clear();
8477
}
8578

8679
stack.iter().map(|v| v.last().unwrap()).collect()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /