Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Can you pass? solution in Uncategorized category for Can You Pass? by capback250
# migrated from python 2.7
def wrapper(field, start):
start_number = field[start[0]][start[1]]
listedField = []
for string in [list(x) for x in field]:
temp = []
for c in string:
if c != start_number:
temp.append("+")
else:
temp.append(repr(start_number))
temp.insert(0, "+")
temp.append("+")
listedField.append(temp)
width = len(listedField[0])
listedField.insert(0, ["+"]*width)
listedField.append(["+"]*width)
return listedField
def simple_checker(field, start):
string_field = []
for st in field:
for c in st:
string_field.extend([c])
return True if string_field.count(field[start[0]][start[1]]) >= len(field)*len(field[0])-2 else False
def search(field, start, target):
if start == target:
return True
if field[start[0]][start[1]] == "+":
return False
if field[start[0]][start[1]] == ".":
return False
field[start[0]][start[1]] = "."
found = search(field, [start[0]-1, start[1]], target) or search(field, [start[0], start[1]-1], target) or \
search(field, [start[0], start[1]+1], target) or search(field, [start[0]+1, start[1]], target)
return True if found else False
def can_pass(field, start, target):
new_start = [start[0]+1, start[1]+1 ]
new_target = [target[0]+1, target[1]+1]
return search(wrapper(field, start), new_start, new_target)
Nov. 14, 2015