Skip to content

Commit 2da61ab

Browse files
authored
Merge pull request #1 from maryamdkh/maryamdkh-patch-1
Update challenge.py
2 parents 80d9e60 + 7234530 commit 2da61ab

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tmu_ctf_too_many_challenge/challenge.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
numbers = []
2+
dictionary ={}
3+
24
print ('starting')
35
with open("numbers.txt") as f:
46
content = f.readlines()
57
for n in content:
6-
numbers.append(int(n.strip()))
8+
dictionary[int(n.strip())] = 0
9+
10+
711
print ('numbers are ready')
812

13+
14+
915
def func(x):
1016
print ('func started for %s' % x)
1117
# Returns the number of distinct pairs (y, z) from the numbers in the file "numbers.txt" whose y != z and (y + z) == x
1218
# Note that two pairs (y, z) and (z, y) are considered the same and are counted only once
1319
ans = set()
1420
step = 0
15-
for i in numbers:
21+
for i in dictionary:
1622
j = x - i # we are looking for j where j+i == x
17-
if j in numbers:
23+
if j in dictionary:
1824
if j == i:
1925
continue
2026
elif j > i:
2127
ans.add((j,i))
2228
else:
2329
ans.add((i,j))
30+
31+
print(len(ans) )
2432
return len(ans)
2533

2634

0 commit comments

Comments
 (0)