-
-
Save trthatcher/21418e2eb0dbd64922e4 to your computer and use it in GitHub Desktop.
This file contains 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
1 | |
2 | |
3 | |
4 | |
6 | |
3 | |
2 | |
5 | |
76 | |
567 | |
23 | |
54 | |
4234 |
This file contains 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
import sys | |
list_of_integers = [] | |
for string_value in open('list_of_integers', 'r').read().splitlines(): | |
list_of_integers.append(int(string_value)) | |
def populate_dictionary(dictionary, list_of_integers): | |
for integer in list_of_integers: | |
dictionary[integer] = True | |
def search_array(dictionary, list_of_integers, sum_value): | |
for integer in list_of_integers: | |
if dictionary.get(sum_value - integer, False): | |
return True | |
return False | |
def subset_sum2(list_of_integers, sum_value): | |
dictionary = {} | |
populate_dictionary(dictionary, list_of_integers) | |
return search_array(dictionary, list_of_integers, sum_value) | |
for string_value in sys.argv[1:]: | |
print subset_sum2(list_of_integers, int(string_value)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did some refactoring: https://gist.github.com/yemutex/dd5e4a63769c62a347b3