Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
brute force and random.choice solution in Clear category for Ore In The Desert by fokusd
import math
import random
def checkio(previous):
possible = []
for x in range(10):
for y in range(10):
if all(round(math.sqrt((x - p[0]) ** 2 + (y - p[1]) ** 2)) == p[2] for p in previous):
possible.append([x, y])
return random.choice(possible)
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"
Nov. 30, 2018
Comments: