Browse Source

Some inputs perform better picking one of the next best rides

instead of picking the next best ride according to our score
function

With the few performing better, total score is now past 48M.
Guillaume Koenig 7 years ago
parent
commit
1e502229e8
1 changed files with 27 additions and 11 deletions
  1. 27 11
      main.go

+ 27 - 11
main.go

@@ -133,17 +133,19 @@ func max(a, b int) int {
133 133
 }
134 134
 
135 135
 func Choose(c *Car) *Ride {
136
-	var bestRide *Ride
137
-	bestLenOfRide := 0
138
-	bestTotal := 0
136
+	var bestRides []struct {
137
+		r         *Ride
138
+		lenOfRide int
139
+		total     int
140
+	}
139 141
 	// fmt.Printf("car %d\n", c.ID)
140 142
 	for _, r := range Rides {
141 143
 		if r.used {
142 144
 			continue
143 145
 		}
144
-		if r.Length() > 6000 {
145
-			continue
146
-		}
146
+		// if r.Length() > 6000 {
147
+		// 	continue
148
+		// }
147 149
 		if r.f < c.EarliestFinish(r) {
148 150
 			continue
149 151
 		}
@@ -151,16 +153,30 @@ func Choose(c *Car) *Ride {
151 153
 		lenOfRide := r.length()
152 154
 		total := max(c.distanceTo(r.a, r.b), r.s-c.Arrival) + lenOfRide
153 155
 		// fmt.Printf("%d/%d\n", lenOfRide, total)
154
-		if bestRide == nil || lenOfRide*bestTotal > total*bestLenOfRide {
155
-			bestLenOfRide = lenOfRide
156
-			bestTotal = total
157
-			bestRide = r
156
+		if len(bestRides) == 0 || lenOfRide*bestRides[len(bestRides)-1].total > total*bestRides[len(bestRides)-1].lenOfRide {
157
+			bestRides = append(bestRides, struct {
158
+				r         *Ride
159
+				lenOfRide int
160
+				total     int
161
+			}{r, lenOfRide, total})
162
+			// shitty sort-of-correct-but-quite-incorrect way
163
+			// of picking next best n rides
164
+			n := 3
165
+			if len(bestRides) > n {
166
+				bestRides = bestRides[len(bestRides)-n:]
167
+			}
158 168
 		}
159 169
 	}
160 170
 	// if bestRide != nil {
161 171
 	// 	fmt.Printf("Picking %d %d -> %d %d\n", bestRide.a, bestRide.b, bestRide.x, bestRide.y)
162 172
 	// }
163
-	return bestRide
173
+	if len(bestRides) != 0 {
174
+		// pick the not quite best ride...hey some
175
+		// of the inputs already  give a better score !
176
+		return bestRides[0].r
177
+		//return bestRides[len(bestRides)-1].r
178
+	}
179
+	return nil
164 180
 }
165 181
 
166 182
 func assign() bool {