Problem 83

completed January 19, 2012

Comments

This problem was just like number 82. I just added one more thing to it so that it could go left and made sure that it went from top left to bottom right. Script ran in under 1 second!

Code

small = 10**8
empty = nothing()
visite = [[0,0]]
empty[0][0] = matrix[0][0]
while len(visite) > 0:
	v = visite[0]
	if v[0] != 79:
		visite.append([v[0]+1, v[1]])
		if empty[v[0]][v[1]] + matrix[v[0]+1][v[1]] < empty[v[0]+1][v[1]]:
			empty[v[0]+1][v[1]] = empty[v[0]][v[1]] + matrix[v[0]+1][v[1]]
		else:
			visite.pop()
	if v[0] != 0:
		visite.append([v[0]-1, v[1]])
		if empty[v[0]][v[1]] + matrix[v[0]-1][v[1]] < empty[v[0]-1][v[1]]:
			empty[v[0]-1][v[1]] = empty[v[0]][v[1]] + matrix[v[0]-1][v[1]]
		else:
			visite.pop()
	if v[1] != 79:
		visite.append([v[0], v[1]+1])
		if empty[v[0]][v[1]] + matrix[v[0]][v[1]+1] < empty[v[0]][v[1]+1]:
			empty[v[0]][v[1]+1] = empty[v[0]][v[1]] + matrix[v[0]][v[1]+1]
		else:
			visite.pop()
	if v[1] != 0:
		visite.append([v[0], v[1]-1])
		if empty[v[0]][v[1]] + matrix[v[0]][v[1]-1] < empty[v[0]][v[1]-1]:
			empty[v[0]][v[1]-1] = empty[v[0]][v[1]] + matrix[v[0]][v[1]-1]
		else:
			visite.pop()	
	del visite[0]
	if empty[-1][-1] < small:
		small = empty[-1][-1]
print small