Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Ore In The Desert by freeman_lex
from math import hypot
A = ([i//10, i%10] for i in range(100))
def checkio(M):
global A
if M: A = (i for i in A if round(hypot(i[0]-M[-1][0],i[1]-M[-1][1]))==M[-1][2])
return A.next()
if __name__ == '__main__':
#This part is using only for self-testing.
def check_solution(func, ore):
recent_data = []
for step in range(4):
row, col = func([d[:] for d in recent_data]) # copy the list
if row < 0 or row > 9 or col < 0 or col > 9:
print("Where is our probe?")
return False
if (row, col) == ore:
return True
dist = round(((row - ore[0]) ** 2 + (col - ore[1]) ** 2) ** 0.5)
recent_data.append([row, col, dist])
print("It was the last probe.")
return False
assert check_solution(checkio, (1, 1)), "Example"
assert check_solution(checkio, (9, 9)), "Bottom right"
assert check_solution(checkio, (6, 6)), "Center"
June 30, 2014
Comments: