2012-08-10 11:27:36 +02:00
|
|
|
from __future__ import print_function
|
|
|
|
import random
|
|
|
|
|
|
|
|
def pick_random_elements(xs, n):
|
|
|
|
for i in range(min(n, len(xs))):
|
|
|
|
i1 = random.randrange(i, len(xs))
|
|
|
|
yield xs[i1]
|
|
|
|
xs[i1] = xs[i]
|
|
|
|
|
2012-08-11 02:22:29 +02:00
|
|
|
def manhattan_dist(p0, p1):
|
|
|
|
x0, y0 = p0
|
|
|
|
x1, y1 = p1
|
|
|
|
return abs(x1 - x0) + abs(y1 - y0)
|