-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_duplicate.py
49 lines (36 loc) · 1.2 KB
/
find_duplicate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from random import randint, shuffle
RANGE = 100
def create_test_case():
# get a list from [1 - RANGE]
l = [x for x in range(1, RANGE + 1)]
# randomize the locations of elements in the list
shuffle(l)
# get a random number between [1 - RANGE]
dup = randint(1, RANGE + 1)
# get a random index in the list
i = randint(0, RANGE)
# add the random number to a random index
l.insert(i, dup)
# return the test case and the duplicate (for validating the answer) ;)
return l, dup
def check_answer(assumed_answer, correct_answer):
# return true or false if answer is correct
return assumed_answer == correct_answer
# TODO: find the duplicate value in l
def find_duplicate(l):
# find the answer
answer = 0
# return the answer
return answer
if __name__ == '__main__':
# get the test case and the answer
l, answer = create_test_case()
# find the duplicate
assumed_answer = find_duplicate(l)
# validate the answer
if check_answer(assumed_answer, answer):
print('You found the duplicate!', end=' ')
else:
print('You did NOT find the duplicate!', end=' ')
# give the answer
print('It was "{}"!'.format(answer))