diff --git a/day10/README.md b/day10/README.md index b62c30d5..fabdaf6a 100644 --- a/day10/README.md +++ b/day10/README.md @@ -155,7 +155,6 @@ main() ### [Solution 2 by @vishalshirke7](./Python/permutations1.py) ```python - from itertools import permutations """ @author : vishalshirke7 @@ -185,6 +184,7 @@ String = "123" for each in permutations(String): print(''.join(each)) + ``` ## Java Implementation diff --git a/day11/README.md b/day11/README.md index 48d18774..2a20ceff 100644 --- a/day11/README.md +++ b/day11/README.md @@ -270,7 +270,6 @@ public class longestCommonSubstring { ## Python Implementation ### [Solution using dynamic programming](./Python/lcs.py) - ```python """ @author : vishalshirke7 @@ -355,4 +354,6 @@ def longest_common_substring(str1, str2): print_output("abcdefg", "xyabcz") print_output("XYXYXYZ", "XYZYX") print_output("abcd", "efgh") -``` \ No newline at end of file +``` + + diff --git a/day13/Python/factorial.py b/day13/Python/factorial.py new file mode 100644 index 00000000..dcd901f3 --- /dev/null +++ b/day13/Python/factorial.py @@ -0,0 +1,16 @@ +""" + @author : vishalshirke7 + @date : 07/01/2019 +""" + + +def factorial(no): + if no <= 1: + return 1 + else: + return no * factorial(no - 1) + + +n = int(input()) +print("factorial of %d is %d" % (n, factorial(n))) + diff --git a/day13/Python/fibonacci.py b/day13/Python/fibonacci.py new file mode 100644 index 00000000..77b30671 --- /dev/null +++ b/day13/Python/fibonacci.py @@ -0,0 +1,31 @@ +""" + @author : vishalshirke7 + @date : 07/01/2019 +""" + + +# Fibonacci Series using Dynamic Programming +def fibonacci(n): + if n <= 1: + return n + else: + if fib_series[n - 1] == 0: + fib_series[n - 1] = fibonacci(n - 1) + + if fib_series[n - 2] == 0: + fib_series[n - 2] = fibonacci(n - 2) + + fib_series[n] = fib_series[n - 2] + fib_series[n - 1] + return fib_series[n] + + +n = int(input()) +fib_series = [0, 1] +while len(fib_series) < n + 1: + fib_series.append(0) +print(fibonacci(n)) +if n == 0: + print(0) +else: + print(", ".join(map(str, fib_series))) + diff --git a/day13/README.md b/day13/README.md index a531c6a1..e4b96744 100644 --- a/day13/README.md +++ b/day13/README.md @@ -114,6 +114,29 @@ int main() return 0; } ``` + +### Python Implementation + +#### [Solution by @vishalshirke7](./Python/factorial.py) +```python +""" + @author : vishalshirke7 + @date : 07/01/2019 +""" + + +def factorial(no): + if no <= 1: + return 1 + else: + return no * factorial(no - 1) + + +n = int(input()) +print("factorial of %d is %d" % (n, factorial(n))) + +``` + *** *** @@ -230,4 +253,41 @@ int main() cout<<"The "<