mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Implement 2022 day 11 part 1
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
//! Common helper utilities to all days
|
||||
|
||||
use std::cmp::Ordering;
|
||||
|
||||
use anyhow::Result;
|
||||
use nom::combinator::map;
|
||||
use nom::error::ErrorKind;
|
||||
@@ -116,3 +118,18 @@ where
|
||||
(b, a)
|
||||
}
|
||||
}
|
||||
|
||||
/// Some magic to get two mutable references into the same slice
|
||||
pub fn get_both<T>(slice: &mut [T], first: usize, second: usize) -> (&mut T, &mut T) {
|
||||
match first.cmp(&second) {
|
||||
Ordering::Greater => {
|
||||
let (begin, end) = slice.split_at_mut(first);
|
||||
(&mut end[0], &mut begin[second])
|
||||
}
|
||||
Ordering::Less => {
|
||||
let (begin, end) = slice.split_at_mut(second);
|
||||
(&mut begin[first], &mut end[0])
|
||||
}
|
||||
Ordering::Equal => panic!("Tried to get the same index twice {first}"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user