Skip to content

Commit

Permalink
Python Implementation of Day 11 problem (#115)
Browse files Browse the repository at this point in the history
* Add @aaditkamat as a contributor

* Add Ruby code for Day 1: FizzBuzz problem

* Add Ruby code for Day 2: String reverse problem

* Update README.md for Day 2

* Modify Ruby code and README

* Add condition for nil and wrong type edge cases

* Add a seperate Ruby source code file for palindrome

* Modify code for reverse.rb

* Add seperate palindrome and reverse code sections in README

* Update gitignore

* Refactor palindrome.rb and rename heading in README

* Add solution for Day 3: Hamming Problem

* Add condition for strings of unequal lengths

* Update README

* Change project name and owner in.all-contributorsrc

* Remove merge conflict lines

* Add @shivank86 as a contributor

* Add C++ files for different patterns

* Add author and date comments at the top of C++ files

* Update README.md

* Add solution for Day 6 Problem in Python

* Update README

* Refactor code files

* Modify string representation of output in python files

* Add Ruby solutions for Day 6 problem

* Update README for Ruby code

* Add first version of solutions for Day 7 problem in C++, Java & Ruby

* Modify solutions

* Update Day 7 README

* Remove merge conflicts from CONTRIBUTORS.md

* Add back removed lines in CONTRIBUTORS.md

* Add code sections contributed by @imkaka to day 6 README

* Update README.md

* Add C++ solution

* Add Day 8 solution in C++

* Add Day 8 solution in Java

* Add Day 8 solution in Ruby

* Add Day 8 solution in Python

* Add credits at the top of the code

* Update README

* Update C++ implementation

* Update Python implementation

* Add solution for Day 10: String Permutation Problem in Python

Signed-off-by: Aadit Rahul Kamat <aadit.k12@gmail.com>

* Update Day 10 README

Signed-off-by: Aadit Rahul Kamat <aadit.k12@gmail.com>

* Change heading in README and remove empty directory in day 9

Signed-off-by: Aadit Rahul Kamat <aadit.k12@gmail.com>

* Update README.md

* Add solution to Day 11 problem in Python

* added code 11 (#121)

* day 11 (#117)

* Python solution for day 10 and day 11 (#114)

* Add @vishalshirke7 as a contributor

* Update @vishalshirke7 as a contributor

* Added python solutions for Day 4

* modified readme

* Add @Vishal

* reverted adding as a contributor

* Update README.md

* Update CONTRIBUTORS.md

* Update CONTRIBUTORS.md

* Added python solutions for day 7

* Edited python solution for day 7

* Edited python solution for day 7

* Added python solution for day 10

* Changed readme for day 10

* minor changes

* Python solution for day 11

* Python solution for day10 and day11

* Add Day 10 & Day 11 - Java Implementation (#116)

* Update @chaitanya-bhojwani as a contributor

* Java Implementation

* Add day 10 and day 11

* Add day 12

* Update day 11 README

Signed-off-by: Aadit Rahul Kamat <aadit.k12@gmail.com>
  • Loading branch information
Aadit Kamat authored and MadhavBahl committed Jan 4, 2019
1 parent 1c181f4 commit 8cefa4c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
27 changes: 27 additions & 0 deletions day11/Python/longest_common_substring.py
@@ -0,0 +1,27 @@
'''
@author: aaditkamat
@date: 03/01/2019
'''
def print_output(str1, str2):
print(f'The longest common substring in {str1} and {str2} is: {longest_common_substring(str1, str2)}')

def substrings(string):
lst = []
n = len(string)
for i in range(1, n + 1):
for j in range(n + 1 - i):
lst.append(string[j : j + i])
print(set(lst))
return set(lst)

def longest_common_substring(str1, str2):
str1_substrings = substrings(str1)
str2_substrings = substrings(str2)
common_substrings = str1_substrings & str2_substrings
if len(common_substrings) == 0:
common_substrings.add("")
return max(common_substrings, key = lambda x: len(x))

print_output("abcdefg", "xyabcz")
print_output("XYXYXYZ", "XYZYX")
print_output("abcd", "efgh")
32 changes: 32 additions & 0 deletions day11/README.md
Expand Up @@ -249,4 +249,36 @@ def lcs(str1, str2):


lcs(*(input().split()))
```

### [Solution 2](./Python/lcs.py)

```python
'''
@author: aaditkamat
@date: 03/01/2019
'''
def print_output(str1, str2):
print(f'The longest common substring in {str1} and {str2} is: {longest_common_substring(str1, str2)}')

def substrings(string):
lst = []
n = len(string)
for i in range(1, n + 1):
for j in range(n + 1 - i):
lst.append(string[j : j + i])
print(set(lst))
return set(lst)

def longest_common_substring(str1, str2):
str1_substrings = substrings(str1)
str2_substrings = substrings(str2)
common_substrings = str1_substrings & str2_substrings
if len(common_substrings) == 0:
common_substrings.add("")
return max(common_substrings, key = lambda x: len(x))

print_output("abcdefg", "xyabcz")
print_output("XYXYXYZ", "XYZYX")
print_output("abcd", "efgh")
```

0 comments on commit 8cefa4c

Please sign in to comment.