diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2017-12-20 07:30:45 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2017-12-20 07:30:45 +0200 |
commit | f9f79a03b575cfe94b73a602df0735b6d5236642 (patch) | |
tree | 84d07bf6b66fb282dfa7beeca471ca61f94f92c6 /src/lib.rs | |
parent | c59a26fec18b995e3dafeff764f25da884f02e3e (diff) |
Day 20: Colliding points in 3D
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -151,6 +151,31 @@ impl Direction { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct Point3d { + pub x: i32, + pub y: i32, + pub z: i32 +} + +impl std::ops::Add for Point3d { + type Output = Point3d; + + fn add(self, other: Point3d) -> Point3d { + Point3d { + x: self.x + other.x, + y: self.y + other.y, + z: self.z + other.z + } + } + +} + +impl Point3d { + pub fn manhattan_distance(&self) -> i32 { + self.x.abs() + self.y.abs() + self.z.abs() + } +} pub fn knot_hash(input: &String) -> String { let suffix: [usize; 5] = [17, 31, 73, 47, 23]; |