Created
August 22, 2013 22:49
-
-
Save ahoulgrave/6313765 to your computer and use it in GitHub Desktop.
Metemática 1 - Guía 1 - Ej. 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'hormiga' | |
rango = [10,11] | |
verdulerias = [ | |
[0,3], | |
[2,3], | |
[1,8], | |
[7,9], | |
[7,1], | |
[8,0], | |
[9,0] | |
] | |
distancia_min = None | |
coords_min = [] | |
def modulo(n): | |
if n < 0: | |
n = n*(-1) | |
return n | |
for x in range(0,rango[0]): | |
for y in range(0,rango[1]): | |
#print "%d,%d" % (x,y,) | |
dist_total = 0 | |
for verduleria in verdulerias: | |
dist_x = modulo(x - verduleria[0]) | |
dist_y = modulo(y - verduleria[1]) | |
dist_total += dist_x+dist_y | |
if distancia_min is None or dist_total < distancia_min: | |
coords_min = [x,y] | |
distancia_min = dist_total | |
print "La distancia minima seria de %d cuadras, en las coordenadas %d,%d" % (distancia_min, coords_min[0], coords_min[1],) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment