Skip to content

Commit

Permalink
Challenge_7
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbotello committed Jan 6, 2017
1 parent 1e81805 commit cac5714
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
20 changes: 20 additions & 0 deletions challenge_7/python/alexbotello/README.md
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
18 changes: 18 additions & 0 deletions challenge_7/python/alexbotello/missing_num.py
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))
19 changes: 19 additions & 0 deletions challenge_7/python/alexbotello/tests.py
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()

0 comments on commit cac5714

Please sign in to comment.