forked from YearOfProgramming/2017Challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e81805
commit cac5714
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
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 file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Find The Missing Number | ||
### Language Version (Python 3.6.0) | ||
|
||
### Compile | ||
|
||
``` | ||
python tests.py | ||
``` | ||
|
||
``` | ||
python missing_num.py | ||
``` | ||
|
||
### How To Use | ||
|
||
Run tests.py to check against unit test | ||
|
||
Run missing_num.py to test your own implementation | ||
- First line of input is the size of the list | ||
- Subsequent inputs are the values of the list |
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 file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
def find_missing_num(array): | ||
|
||
sum_of_array = 0 | ||
sum_of_indexes = 0 | ||
|
||
for a in array: | ||
sum_of_array += a | ||
for b in range(1, len(array) + 1): | ||
sum_of_indexes += b | ||
|
||
return sum_of_indexes - sum_of_total | ||
|
||
if __name__ == "__main__": | ||
|
||
n = int(input()) | ||
nums = [int(input()) for _ in range(n)] | ||
print() | ||
print(find_missing_num(nums)) |
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 file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import unittest | ||
from missing_num import find_missing_num | ||
|
||
class Tests(unittest.TestCase): | ||
|
||
def test1(self): | ||
self.assertEquals(find_missing_num([0,1,3]), 2) | ||
|
||
def test2(self): | ||
self.assertEqual(find_missing_num([0,2,3,4,1,8,7,6,5,9,11,10,12,13,15]), 14) | ||
|
||
def test3(self): | ||
self.assertEqual(find_missing_num([1,2,3]), 0) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |