Explorar o código

add Ride.Length function

Gildas Chabot %!s(int64=7) %!d(string=hai) anos
pai
achega
79428f2873
Modificáronse 1 ficheiros con 13 adicións e 0 borrados
  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) }