Przeglądaj źródła

add Ride.Length function

Gildas Chabot 7 lat temu
rodzic
commit
79428f2873
1 zmienionych plików z 13 dodań i 0 usunięć
  1. 13 0
      main.go

+ 13 - 0
main.go

@@ -30,6 +30,19 @@ type Ride struct {
30
 	used bool
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
 type ByEndtime []*Ride
46
 type ByEndtime []*Ride
34
 
47
 
35
 func (rs ByEndtime) Len() int      { return len(rs) }
48
 func (rs ByEndtime) Len() int      { return len(rs) }