Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def explore(arr, combination, i, j):
- """
- for each column in the combination we have to find
- compare it with what is present in the map (arr)
- """
- for row in combination:
- for count, item in enumerate(row):
- # compare the map with the combination value we're up to
- # if it doesn;t match, return False and stop
- if arr[i+count][j] != item:
- return False
- j+=1
- return True
- def find_combination_in_arr(arr, combination, ):
- for i, row in enumerate(arr):
- for j, item in enumerate(row):
- # if we have found the start of the combination, then start exploring
- if item == combination[0][0]:
- if explore(arr, combination, i, j):
- return "FOUND IT!"
- # the map we need to search
- arr = [
- [1, 1, 2, 3, 4, 1, 1],
- [1, 1, 5, 6, 7, 1, 1],
- [1, 1, 2, 7, 4, 1, 1],
- [1, 1, 7, 8, 6, 1, 1]
- ]
- # the combination we need to find
- combination = [
- [2, 5, 2, 7],
- [3, 6, 7, 8],
- [4, 7, 4, 6]
- ]
- find_combination_in_arr(arr, combination)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement