a-robots-conundrum/arobotsconundrum/misc.py

14 lines
309 B
Python
Raw Normal View History

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]
def manhattan_dist(p0, p1):
x0, y0 = p0
x1, y1 = p1
return abs(x1 - x0) + abs(y1 - y0)