Created
November 14, 2015 03:19
-
-
Save farvour/a6756e1ee7ce4f7b75aa to your computer and use it in GitHub Desktop.
1 to 100 Unique Sum
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
a = [1, 99, 98, 2, 7, 93, 99, 1] | |
o = [] | |
print('Original input: {}'.format(a)) | |
m = {} | |
for n in a: | |
if n not in m: | |
m[n] = 1 | |
else: | |
m[n] += 1 | |
print('Map: {}'.format(m)) | |
for n, c in m.items(): | |
print('{} seen {} times'.format(n, c)) | |
for i in a: | |
for z, c in m.items(): | |
if m[z] > 0 and m[i] > 0 and i + z == 100: | |
o.append((i, z)) | |
m[z] -= 1 | |
m[i] -= 1 | |
print('Output: {}'.format(o)) |
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
Original input: [1, 99, 98, 2, 7, 93, 99, 1] | |
Map: {1: 2, 98: 1, 99: 2, 7: 1, 2: 1, 93: 1} | |
1 seen 2 times | |
98 seen 1 times | |
99 seen 2 times | |
7 seen 1 times | |
2 seen 1 times | |
93 seen 1 times | |
New map: {1: 1, 98: 1, 99: 1, 7: 1, 2: 1, 93: 1} | |
New map: {1: 0, 98: 1, 99: 0, 7: 1, 2: 1, 93: 1} | |
New map: {1: 0, 98: 0, 99: 0, 7: 1, 2: 0, 93: 1} | |
New map: {1: 0, 98: 0, 99: 0, 7: 0, 2: 0, 93: 0} | |
Output: [(1, 99), (99, 1), (98, 2), (7, 93)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment