Skip to content

Commit

Permalink
[python]challenge_[6](Pending) (YearOfProgramming#225)
Browse files Browse the repository at this point in the history
* appended readme

* typo fix

* Update Solution.py

* Update README.md

* updated readme

* [Python]Challenge_7(Unreviewed)
  • Loading branch information
MJUIUC committed Jan 7, 2017
1 parent cc3d63d commit b546368
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ When You do perform a pull request, you should set the title of it so that other
- If your code is actively being reviewed, your pull request title should look like this: `[language]challenge_[chalNumber](Pending)`
- If your reviewer agrees that your change is good to merge, set your pull request to this: `[language]challenge_[chalNumber](ReadyForMerge)` and a mod will merge your code to the main repository.

**Please check your github notifications frequently**
Once you've seen that you've been given an approval by any two people, write a comment aknowledging that you've seen them. Even a simple "Seen" will do.

Taking this approach to code review will help to streamline the process and make reviews easier for everyone involved. Take the time to check your github notifications so that you can check to see if anyone has reviewed your code yet.

10 changes: 10 additions & 0 deletions challenge_6/python/mjuiuc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#Solution

I think I got it. All my code does is stop everytime the range in the list breaks and puts the start and end of that range into
a list and then returns that list. Of course there are a couple of statements that check for special cases, but overall it seems
ok to me. I did get stuck on understanding what the prompt meant by ranges untill I noticed that it was just consecutive numbers...
whoops! Either way, it's all done now and I implemented a unit test of the given test cases and one really long one I made.

If you'd like to use my unit tests, all you have to do is implement your solution in my Solution.py. Change the code under the compRange function using the input parameters given. Copy my test.py and Solution.py before you edit them. Please don't make a pull request that writes over the code in my file.

`Marcus Jefferson`
28 changes: 28 additions & 0 deletions challenge_6/python/mjuiuc/Solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Writing solution for this range problem

class solution(object):
def compRange(self,nums):
# nums is of type list()
# nums contains only integers in ascending order
# this function should return the list of collapsed ranges

if nums == None:
return None
if len(nums) == 1:
return []

resList = list()
start = nums[0]
end = 0
newList = list()
for i in xrange(1,len(nums)):
if nums[i] != int(nums[i-1] + 1):
end = nums[i-1]
resList.append("{s}->{e}".format(s = start, e = end))
start = nums[i]

if i == len(nums) - 1:
end = nums[i]
resList.append("{s}->{e}".format(s = start, e = end))

return resList
52 changes: 52 additions & 0 deletions challenge_6/python/mjuiuc/test.py

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions challenge_7/python/mjuiuc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Solution

I think I got it figured out. All I had to do was take the sum of the length of the list and then the sum of all the numbers in the list, find the difference betweend those results, and then return the difference modded by the length of the list. The function meets runtime and space requirements.

I included some test cases in my solution.
9 changes: 9 additions & 0 deletions challenge_7/python/mjuiuc/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def solution(nums):
n = len(nums) + 1
sums = 0
Summation = 0
for i in nums:
sums += i
for i in xrange(0,n+1):
Summation += i
return (Summation - sums) % n
28 changes: 28 additions & 0 deletions challenge_7/python/mjuiuc/test.py

Large diffs are not rendered by default.

0 comments on commit b546368

Please sign in to comment.