mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-26 13:20:32 +01:00
Partial solution for day 15 part 1.
Partial in the sense that it doesn't actually work for my input, only for the samples.
This commit is contained in:
@@ -3,6 +3,8 @@ use std::hash::Hash;
|
||||
use std::io;
|
||||
use std::io::Read;
|
||||
use std::str::FromStr;
|
||||
use std::ops::Add;
|
||||
use std::ops::Sub;
|
||||
|
||||
/// Apply Erathostenes's sieve to the supplied array
|
||||
///
|
||||
@@ -65,6 +67,15 @@ pub fn read_single_input<T>(input: &mut Read) -> T
|
||||
buf.trim().parse().unwrap()
|
||||
}
|
||||
|
||||
/// Compute the manhattan distance between two points of arbitrary type.
|
||||
pub fn manhattan_distance<T>(a: (T, T), b: (T, T)) -> T
|
||||
where T: Copy + Add<Output=T> + Sub<Output=T> + Ord
|
||||
{
|
||||
let (xa, ya) = a;
|
||||
let (xb, yb) = b;
|
||||
xa.max(xb) + ya.max(yb) - xa.min(xb) - ya.min(yb)
|
||||
}
|
||||
|
||||
|
||||
/// An interface to count elements in particular categories.
|
||||
pub trait GroupingCount {
|
||||
|
||||
Reference in New Issue
Block a user