Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
dd79ee7
commit 9080b91
Showing
4 changed files
with
141 additions
and
2 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,10 @@ | ||
from itertools import permutations | ||
""" | ||
@author : vishalshirke7 | ||
@date : 02/01/2019 | ||
""" | ||
|
||
ip_str = input() | ||
perm = permutations(list(ip_str), len(ip_str)) | ||
for i in set(list(perm)): | ||
print("".join(map(str, i))) |
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
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,51 @@ | ||
""" | ||
@author : vishalshirke7 | ||
@date : 03/01/2019 | ||
""" | ||
|
||
|
||
def lcs(str1, str2): | ||
m, n = len(str1), len(str2) | ||
|
||
L = [[0 for y in range(n + 1)] for x in range(m + 1)] | ||
|
||
for i in range(m + 1): | ||
for j in range(n + 1): | ||
if i == 0 or j == 0: | ||
L[i][j] = 0 | ||
elif str1[i - 1] == str2[j - 1]: | ||
L[i][j] = L[i - 1][j - 1] + 1 | ||
else: | ||
L[i][j] = max(L[i - 1][j], L[i][j - 1]) | ||
|
||
index = L[m][n] | ||
|
||
# Create a character array to store the lcs string | ||
lcs_str = [""] * (index + 1) | ||
lcs_str[index] = "" | ||
|
||
i = m | ||
j = n | ||
while i > 0 and j > 0: | ||
|
||
# If current character in X[] and Y are same, then | ||
# current character is part of LCS | ||
if str1[i - 1] == str2[j - 1]: | ||
lcs_str[index - 1] = str1[i - 1] | ||
i -= 1 | ||
j -= 1 | ||
index -= 1 | ||
|
||
# If not same, then find the larger of two and | ||
# go in the direction of larger value | ||
elif L[i - 1][j] > L[i][j - 1]: | ||
i -= 1 | ||
else: | ||
j -= 1 | ||
|
||
print("LCS of " + str1 + " and " + str2 + " is -" + "".join(lcs_str)) | ||
|
||
|
||
lcs(*(input().split())) | ||
|
||
|
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