Created
July 10, 2019 11:48
-
-
Save nagy135/e5844eae50efbbd2dd30a835bb05eb12 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def brute_search( arr, score, my_min, path): | |
if len(arr) == 0: | |
return score, path | |
if my_min is None: | |
take, take_path = brute_search( arr[1:], 1, arr[0], [(1, arr[0])] ) | |
ignore, ignore_path = brute_search( arr[1:], 0, None, []) | |
if take > ignore: | |
return take,take_path | |
else: | |
return ignore,ignore_path | |
if arr[0] > my_min: | |
if len(arr) >= 1: | |
ignore, ignore_path = brute_search( arr[1:], score, my_min, path ) | |
take, take_path = brute_search( arr[1:], score+1, arr[0], path + [(score+1, arr[0])] ) | |
if take > ignore: | |
return take,take_path | |
else: | |
return ignore,ignore_path | |
else: | |
return score, path | |
else: | |
return brute_search( arr[1:], score, my_min, path ) | |
pole = [10, 22, 9, 33, 21, 50, 41, 60, 80] | |
for pair in brute_search( pole, 0, None, [] )[1]: | |
print( "index: {}, element: {}".format( *pair ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment