Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. def explore(arr, combination, i, j):
  2. """
  3. for each column in the combination we have to find
  4. compare it with what is present in the map (arr)
  5. """
  6. for row in combination:
  7. for count, item in enumerate(row):
  8.  
  9. # compare the map with the combination value we're up to
  10. # if it doesn;t match, return False and stop
  11. if arr[i+count][j] != item:
  12. return False
  13. j+=1
  14. return True
  15.  
  16. def find_combination_in_arr(arr, combination, ):
  17. for i, row in enumerate(arr):
  18. for j, item in enumerate(row):
  19.  
  20. # if we have found the start of the combination, then start exploring
  21. if item == combination[0][0]:
  22. if explore(arr, combination, i, j):
  23. return "FOUND IT!"
  24.  
  25. # the map we need to search
  26. arr = [
  27. [1, 1, 2, 3, 4, 1, 1],
  28. [1, 1, 5, 6, 7, 1, 1],
  29. [1, 1, 2, 7, 4, 1, 1],
  30. [1, 1, 7, 8, 6, 1, 1]
  31. ]
  32.  
  33. # the combination we need to find
  34. combination = [
  35. [2, 5, 2, 7],
  36. [3, 6, 7, 8],
  37. [4, 7, 4, 6]
  38. ]
  39.  
  40. find_combination_in_arr(arr, combination)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement