ソースを参照

add Ride.Length function

Gildas Chabot 7 年 前
コミット
79428f2873
共有1 個のファイルを変更した13 個の追加0 個の削除を含む
  1. 13 0
      main.go

+ 13 - 0
main.go

@@ -30,6 +30,19 @@ type Ride struct {
30 30
 	used bool
31 31
 }
32 32
 
33
+func (r Ride) Length() int {
34
+	xdist := r.a - r.x
35
+	if xdist < 0 {
36
+		xdist = -xdist
37
+	}
38
+	ydist := r.b - r.y
39
+	if ydist < 0 {
40
+		ydist = -ydist
41
+	}
42
+
43
+	return xdist + ydist
44
+}
45
+
33 46
 type ByEndtime []*Ride
34 47
 
35 48
 func (rs ByEndtime) Len() int      { return len(rs) }