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:
2018-12-15 18:02:16 +01:00
parent bcccc85073
commit 069e381aeb
9 changed files with 329 additions and 4 deletions

View File

@@ -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 {