From c77b47fd36448feba907f7d49b85724f03c48361 Mon Sep 17 00:00:00 2001 From: Himanshu Nachane Date: Tue, 25 Apr 2017 20:42:05 +0530 Subject: [PATCH 01/12] Solution to issue #18 in Python --- solutions/18.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 solutions/18.py diff --git a/solutions/18.py b/solutions/18.py new file mode 100644 index 0000000..722fb62 --- /dev/null +++ b/solutions/18.py @@ -0,0 +1,20 @@ +#Himanshu Nachane (@Himanshu1495) +'''return missing number in an input array of consecutively increasing numbers. + +i: [5,6,8,9] +o: 7 +''' + +#get space seperated integers from user +arr = map(int,raw_input().split()) +#get first element of array +start = arr[0] +#get last element of array +end = arr[-1] +#create new array by iterating from start element to end element +new_arr = [x for x in range(start,end+1)] +#print answer +print sum(new_arr)-sum(arr) + + + From 30686639037b49ed1ca3311ae35f56f20b1354f0 Mon Sep 17 00:00:00 2001 From: Himanshu Nachane Date: Wed, 26 Apr 2017 23:00:15 +0530 Subject: [PATCH 02/12] Modified the code,function created to allow passing the parameters --- solutions/18.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/solutions/18.py b/solutions/18.py index 722fb62..e5e353e 100644 --- a/solutions/18.py +++ b/solutions/18.py @@ -5,16 +5,16 @@ o: 7 ''' -#get space seperated integers from user -arr = map(int,raw_input().split()) -#get first element of array -start = arr[0] -#get last element of array -end = arr[-1] -#create new array by iterating from start element to end element -new_arr = [x for x in range(start,end+1)] -#print answer -print sum(new_arr)-sum(arr) - +def missing_num(arr): + #get first element of array + start = arr[0] + #get last element of array + end = arr[-1] + #create new array by iterating from start element to end element + new_arr = [x for x in range(start,end+1)] + #return answer + return sum(new_arr)-sum(arr) +#example to run the code +print missing_num([5,6,8,9]) From 01c3ab9ce704380d986ce3ff854518df2c44ada3 Mon Sep 17 00:00:00 2001 From: Himanshu Nachane Date: Thu, 27 Apr 2017 21:46:36 +0530 Subject: [PATCH 03/12] Tests for issue #18 added. SKELETON CODE to test python(2.7) solutions created. --- solutions/pythontest_skeleton.py | 15 +++++++++++++++ test/test18.py | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 solutions/pythontest_skeleton.py create mode 100644 test/test18.py diff --git a/solutions/pythontest_skeleton.py b/solutions/pythontest_skeleton.py new file mode 100644 index 0000000..e00f185 --- /dev/null +++ b/solutions/pythontest_skeleton.py @@ -0,0 +1,15 @@ +#Created by Himanshu Nachane (@Himanshu1495) + +import unittest + +#Write your function here + +class MyTest(unittest.TestCase): + def test1(self): + self.assertEqual( #call your function by passing parameters , #write the correct answer of the test here ) + + #to add more tests, write more functions here like def test2(self) + #Remember to pass self as a parameter in the function. + #The name of the function can be anything like def hey(self) + +unittest.main() \ No newline at end of file diff --git a/test/test18.py b/test/test18.py new file mode 100644 index 0000000..9fa633c --- /dev/null +++ b/test/test18.py @@ -0,0 +1,21 @@ +import unittest + +def missing_num(arr): + #get first element of array + start = arr[0] + #get last element of array + end = arr[-1] + #create new array by iterating from start element to end element + new_arr = [x for x in range(start,end+1)] + #print answer + return sum(new_arr)-sum(arr) + +class MyTest(unittest.TestCase): + def test1(self): + self.assertEqual(missing_num([10,11,12,14,15,16]),13) + def test2(self): + self.assertEqual(missing_num([125,126,128,129,130]),127) + def test3(self): + self.assertEqual(missing_num([1125,1127,1128,1129,1130]),1126) + +unittest.main() From 83580c3ae8fc2fc44da8234994a211eb570d4ae9 Mon Sep 17 00:00:00 2001 From: Himanshu Nachane Date: Fri, 5 May 2017 12:24:18 +0530 Subject: [PATCH 04/12] Modification to 18.py Comments in the code have been removed. for loop has been used as discussed. --- solutions/18.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/solutions/18.py b/solutions/18.py index e5e353e..251657e 100644 --- a/solutions/18.py +++ b/solutions/18.py @@ -6,14 +6,12 @@ ''' def missing_num(arr): - #get first element of array - start = arr[0] - #get last element of array - end = arr[-1] - #create new array by iterating from start element to end element - new_arr = [x for x in range(start,end+1)] - #return answer - return sum(new_arr)-sum(arr) + first_element = arr[0] + last_element = arr[-1] + new_sum = 0 + for x in range(first_element,last_element+1): + new_sum += x + return new_sum - sum(arr) #example to run the code print missing_num([5,6,8,9]) From 80f3222d1b857f79023eb9875ff28c5b78d9274f Mon Sep 17 00:00:00 2001 From: Himanshu Nachane Date: Fri, 5 May 2017 12:27:50 +0530 Subject: [PATCH 05/12] Modification to test18.py Tests have been modified as per the modified code of 18.py . The code has been tested and it passed the test cases. --- test/test18.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/test/test18.py b/test/test18.py index 9fa633c..5623cb8 100644 --- a/test/test18.py +++ b/test/test18.py @@ -1,14 +1,12 @@ import unittest def missing_num(arr): - #get first element of array - start = arr[0] - #get last element of array - end = arr[-1] - #create new array by iterating from start element to end element - new_arr = [x for x in range(start,end+1)] - #print answer - return sum(new_arr)-sum(arr) + first_element = arr[0] + last_element = arr[-1] + new_sum = 0 + for x in range(first_element,last_element+1): + new_sum += x + return new_sum - sum(arr) class MyTest(unittest.TestCase): def test1(self): From 64650de3c2da769a6c5f8ce98307f242357c1905 Mon Sep 17 00:00:00 2001 From: Himanshu Nachane Date: Tue, 9 May 2017 21:13:02 +0530 Subject: [PATCH 06/12] Solution to issue #34 in Python 2.7 --- solutions/34.py | 13 +++++++++++++ test/test34.py | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 solutions/34.py create mode 100644 test/test34.py diff --git a/solutions/34.py b/solutions/34.py new file mode 100644 index 0000000..6d51585 --- /dev/null +++ b/solutions/34.py @@ -0,0 +1,13 @@ +#Himanshu Nachane (@Himanshu1495) +''' +Input: An array, a number +Output: number of times the number shows up in the array. + +Input: [1,2,2,3], 3 +Output: 1 +''' + +def repeating_element(array,number): + return array.count(number) + +print repeating_element([2,3,4,5,3],3) diff --git a/test/test34.py b/test/test34.py new file mode 100644 index 0000000..0a64a4e --- /dev/null +++ b/test/test34.py @@ -0,0 +1,22 @@ +''' +Input: An array, a number +Output: number of times the number shows up in the array. + +Input: [1,2,2,3], 3 +Output: 1 +''' + +import unittest + +def repeating_element(array,number): + return array.count(number) + +class MyTest(unittest.TestCase): + def test1(self): + self.assertEqual(repeating_element([10,1,12,4,16,16],16),2) + def test2(self): + self.assertEqual(repeating_element([-164,170,61,-164,152,44,16,-164],-164),3) + def test3(self): + self.assertEqual(repeating_element([1340,1456,1452,4546,1667,1237],1667),1) + +unittest.main() From e2d1f35c596b84d6f705850c417819235ab84f23 Mon Sep 17 00:00:00 2001 From: Himanshu Nachane Date: Tue, 9 May 2017 21:23:55 +0530 Subject: [PATCH 07/12] Delete 34.py --- solutions/34.py | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 solutions/34.py diff --git a/solutions/34.py b/solutions/34.py deleted file mode 100644 index 6d51585..0000000 --- a/solutions/34.py +++ /dev/null @@ -1,13 +0,0 @@ -#Himanshu Nachane (@Himanshu1495) -''' -Input: An array, a number -Output: number of times the number shows up in the array. - -Input: [1,2,2,3], 3 -Output: 1 -''' - -def repeating_element(array,number): - return array.count(number) - -print repeating_element([2,3,4,5,3],3) From ab97ccf414f53135c275651745d8a779c3d26869 Mon Sep 17 00:00:00 2001 From: Himanshu Nachane Date: Tue, 9 May 2017 21:24:32 +0530 Subject: [PATCH 08/12] Delete test34.py --- test/test34.py | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 test/test34.py diff --git a/test/test34.py b/test/test34.py deleted file mode 100644 index 0a64a4e..0000000 --- a/test/test34.py +++ /dev/null @@ -1,22 +0,0 @@ -''' -Input: An array, a number -Output: number of times the number shows up in the array. - -Input: [1,2,2,3], 3 -Output: 1 -''' - -import unittest - -def repeating_element(array,number): - return array.count(number) - -class MyTest(unittest.TestCase): - def test1(self): - self.assertEqual(repeating_element([10,1,12,4,16,16],16),2) - def test2(self): - self.assertEqual(repeating_element([-164,170,61,-164,152,44,16,-164],-164),3) - def test3(self): - self.assertEqual(repeating_element([1340,1456,1452,4546,1667,1237],1667),1) - -unittest.main() From 7a20b9b38e16baa504ebcccb39e7b0767d83ac48 Mon Sep 17 00:00:00 2001 From: Himanshu Nachane Date: Sat, 13 May 2017 11:54:30 +0530 Subject: [PATCH 09/12] print statement removed from solution --- solutions/18.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/solutions/18.py b/solutions/18.py index 251657e..0830897 100644 --- a/solutions/18.py +++ b/solutions/18.py @@ -13,6 +13,5 @@ def missing_num(arr): new_sum += x return new_sum - sum(arr) -#example to run the code -print missing_num([5,6,8,9]) + From a0d7b6e2de3ec79a55283342b2b545973dd62855 Mon Sep 17 00:00:00 2001 From: Himanshu Nachane Date: Wed, 7 Jun 2017 01:04:25 +0530 Subject: [PATCH 10/12] Test skeleton moved from solutions to tests --- {solutions => test}/pythontest_skeleton.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {solutions => test}/pythontest_skeleton.py (100%) diff --git a/solutions/pythontest_skeleton.py b/test/pythontest_skeleton.py similarity index 100% rename from solutions/pythontest_skeleton.py rename to test/pythontest_skeleton.py From 2b03a34710df9769c56ccc6d24c6c078330fcab7 Mon Sep 17 00:00:00 2001 From: Himanshu Nachane Date: Wed, 14 Jun 2017 00:18:49 +0530 Subject: [PATCH 11/12] Test modified to eliminate redundancy. pythontest_skeleton modified with new changes. Name of solution changed from 18.py to sol18.py to avoid conflict while importing the file for testing --- solutions/{18.py => sol18.py} | 0 test/pythontest_skeleton.py | 5 +++-- test/test18.py | 11 +++-------- 3 files changed, 6 insertions(+), 10 deletions(-) rename solutions/{18.py => sol18.py} (100%) diff --git a/solutions/18.py b/solutions/sol18.py similarity index 100% rename from solutions/18.py rename to solutions/sol18.py diff --git a/test/pythontest_skeleton.py b/test/pythontest_skeleton.py index e00f185..1281ff7 100644 --- a/test/pythontest_skeleton.py +++ b/test/pythontest_skeleton.py @@ -1,8 +1,9 @@ #Created by Himanshu Nachane (@Himanshu1495) - +import sys +sys.path.insert(0,'../solutions/') +from your_file_name import your_function_name import unittest -#Write your function here class MyTest(unittest.TestCase): def test1(self): diff --git a/test/test18.py b/test/test18.py index 5623cb8..164ffa9 100644 --- a/test/test18.py +++ b/test/test18.py @@ -1,13 +1,8 @@ +import sys +sys.path.insert(0,'../solutions/') +from sol18 import missing_num import unittest -def missing_num(arr): - first_element = arr[0] - last_element = arr[-1] - new_sum = 0 - for x in range(first_element,last_element+1): - new_sum += x - return new_sum - sum(arr) - class MyTest(unittest.TestCase): def test1(self): self.assertEqual(missing_num([10,11,12,14,15,16]),13) From 0a2acc58a99115c3aca322a3e05c2aa881722119 Mon Sep 17 00:00:00 2001 From: Himanshu Nachane Date: Wed, 14 Jun 2017 17:50:04 +0530 Subject: [PATCH 12/12] Renamed test18.py to 18.py and deleted pythontest_skeleton --- test/{test18.py => 18.py} | 0 test/pythontest_skeleton.py | 16 ---------------- 2 files changed, 16 deletions(-) rename test/{test18.py => 18.py} (100%) delete mode 100644 test/pythontest_skeleton.py diff --git a/test/test18.py b/test/18.py similarity index 100% rename from test/test18.py rename to test/18.py diff --git a/test/pythontest_skeleton.py b/test/pythontest_skeleton.py deleted file mode 100644 index 1281ff7..0000000 --- a/test/pythontest_skeleton.py +++ /dev/null @@ -1,16 +0,0 @@ -#Created by Himanshu Nachane (@Himanshu1495) -import sys -sys.path.insert(0,'../solutions/') -from your_file_name import your_function_name -import unittest - - -class MyTest(unittest.TestCase): - def test1(self): - self.assertEqual( #call your function by passing parameters , #write the correct answer of the test here ) - - #to add more tests, write more functions here like def test2(self) - #Remember to pass self as a parameter in the function. - #The name of the function can be anything like def hey(self) - -unittest.main() \ No newline at end of file