Solve day 10
This commit is contained in:
parent
ec545d1b06
commit
ab7b9af735
8 changed files with 368 additions and 0 deletions
53
src/lib.rs
53
src/lib.rs
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue