1
0
Fork 0

Solve day 10

This commit is contained in:
Lars Martens 2023-12-10 17:05:29 +01:00
parent ec545d1b06
commit ab7b9af735
Signed by: haselkern
GPG key ID: B5CF1F363C179AD4
8 changed files with 368 additions and 0 deletions

View file

@ -1,5 +1,6 @@
//! This library contains useful helper functions that may be useful in several problems.
use std::ops::{Add, AddAssign};
use std::{
fmt::{Debug, Display},
ops::{Div, Mul, Rem},
@ -91,3 +92,55 @@ where
let gcd = gcd(a, b);
a / gcd * b
}
/// Given a function and a name of a file in the `input` directory,
/// assert that the function applied to the contents of the file returns the expected result.
/// ```
#[macro_export]
macro_rules! assert_example {
($solve:ident, $file:expr, $expected:expr) => {
assert_eq!(
$solve(include_str!(concat!("../../input/", $file))),
$expected,
"{}, {}",
stringify!($solve),
$file,
)
};
}
#[derive(Default, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct Vec2<T> {
pub x: T,
pub y: T,
}
impl<T> Vec2<T> {
pub fn new(x: T, y: T) -> Self {
Self { x, y }
}
}
impl<T> Add for Vec2<T>
where
T: Add<Output = T>,
{
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self {
x: self.x + rhs.x,
y: self.y + rhs.y,
}
}
}
impl<T> AddAssign for Vec2<T>
where
T: AddAssign,
{
fn add_assign(&mut self, rhs: Self) {
self.x += rhs.x;
self.y += rhs.y;
}
}