Skip to content

time unittest and setify #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions tmu_ctf_too_many_challenge/challenge_by_erfan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
numbers = []
print ('starting')
with open("numbers.txt") as f:
content = f.readlines()
for n in content:
numbers.append(int(n.strip()))
print ('numbers are ready')

def func(x):
print ('func started for %s' % x)
# Returns the number of distinct pairs (y, z) from the numbers in the file "numbers.txt" whose y != z and (y + z) == x
# Note that two pairs (y, z) and (z, y) are considered the same and are counted only once
ans = set()
# step = 0
numbers_set = set(numbers)
for i in numbers_set:
j = x - i # we are looking for j where j+i == x
if j in numbers_set:
if j == i:
continue
elif j > i:
ans.add((j,i))
else:
ans.add((i,j))
return len(ans)


def get_flag(res):
flag = []
for i in range(len(res)):
flag.append(chr(func(res[i])))
flag = ''.join(flag)
return flag


if __name__ == "__main__":
res = [751741232, 519127658, 583555720, 3491231752, 3333111256, 481365731, 982100628, 1001121327, 3520999746,
915725624, 3218509573, 3621224627, 3270950626, 3321456817, 3091205444, 999888800, 475855017, 448213157,
3222412857, 820711846, 3710211491, 3119823672, 3333211607, 812955676, 971211391, 3210953872, 289789909,
781213400, 578265122, 910021887, 653886578, 3712776506, 229812345, 582319118, 1111276998, 1151016390,
700123328, 1074521304, 3210438183, 817210125, 501231350, 753244584, 3240911853, 415234677, 469125436,
592610671, 612980665, 291821367, 344199617, 1011100412, 681623864, 897219249, 3132267885, 565913000,
301203203, 3100544737, 432812663, 1012813485, 510928797, 671553831, 3216409218, 3191288433, 698777123,
3512778698, 810476845, 3102989588, 3621432709, 812321695, 526486561, 378912454, 3316207359, 623111580,
344209171, 537454826, 691277475, 2634678623, 1112182335, 792111856, 762989676, 666210267, 871278369,
581009345, 391231132, 921732469, 717217468, 3101412929, 3101217354, 831912337, 532666530, 701012510,
601365919, 492699680, 2843119525]
print("The flag is", get_flag(res))
15 changes: 15 additions & 0 deletions tmu_ctf_too_many_challenge/test_challenge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unittest
from timeit import timeit

from challenge import func


class TestChallenge(unittest.TestCase):
def test_one_speed(self):
time_of_one_number_solve = timeit(lambda: func(751741232), number=5)/5
self.assertGreater(1, time_of_one_number_solve,
f'To slow {time_of_one_number_solve:.2f} seconds for iter!')


if __name__ == '__main__':
unittest.main()