forked from ArsalanKhairani/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2SumProblem.py
22 lines (19 loc) · 864 Bytes
/
2SumProblem.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
################################################################################
## Copyright(c) Arsalan Khairani, 2014 ##
## 2 Sum Problem ##
## ##
## Algorithm for a hashtable application of 2 Sum ##
################################################################################
def sum2 (hashTable):
count = 0
for x in hashTable.keys():
for t in range(-10000, 10001):
if t - x in hashTable.keys() and (t - x) > x:
count += 1
return count
file = open("algo1-programming_prob-2sum.txt")
Hashtable = {}
for line in file:
entry = int(line.strip('\n'))
Hashtable[entry] = entry
print (sum2(Hashtable))