Skip to content

Commit 9561259

Browse files
Merge branch 'master' into improved_sorting_algo
2 parents 98cc298 + fedb3e7 commit 9561259

33 files changed

+576
-118
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ __pycache__/
77
*.so
88

99
# Distribution / packaging
10+
.vscode/
1011
.Python
1112
env/
1213
build/

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

ArithmeticAnalysis/LUdecomposition.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import math
21
import numpy
32

4-
def LUDecompose (table): #table that contains our data
3+
def LUDecompose (table):
4+
#table that contains our data
55
#table has to be a square array so we need to check first
66
rows,columns=numpy.shape(table)
77
L=numpy.zeros((rows,columns))
@@ -31,4 +31,4 @@ def LUDecompose (table): #table that contains our data
3131
matrix =numpy.array([[2,-2,1],[0,1,2],[5,3,1]])
3232
L,U = LUDecompose(matrix)
3333
print(L)
34-
print(U)
34+
print(U)

ArithmeticAnalysis/NewtonRaphsonMethod.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
# Implementing Newton Raphson method in python
1+
# Implementing Newton Raphson method in Python
22
# Author: Haseeb
33

44
from sympy import diff
55
from decimal import Decimal
6-
from math import sin, cos, exp
76

87
def NewtonRaphson(func, a):
98
''' Finds root from the point 'a' onwards by Newton-Raphson method '''
109
while True:
11-
x = a
1210
c = Decimal(a) - ( Decimal(eval(func)) / Decimal(eval(str(diff(func)))) )
1311

14-
x = c
1512
a = c
13+
1614
# This number dictates the accuracy of the answer
1715
if abs(eval(func)) < 10**-15:
1816
return c
1917

2018

2119
# Let's Execute
2220
if __name__ == '__main__':
23-
# Find root of trignometric fucntion
24-
# Find value of pi
21+
# Find root of trigonometric function
22+
# Find value of pi
2523
print ('sin(x) = 0', NewtonRaphson('sin(x)', 2))
2624

2725
# Find root of polynomial
@@ -30,7 +28,7 @@ def NewtonRaphson(func, a):
3028
# Find Square Root of 5
3129
print ('x**2 - 5 = 0', NewtonRaphson('x**2 - 5', 0.1))
3230

33-
# Exponential Roots
31+
# Exponential Roots
3432
print ('exp(x) - 1 = 0', NewtonRaphson('exp(x) - 1', 0))
3533

3634

Multi_Hueristic_Astar.py renamed to Graphs/Multi_Hueristic_Astar.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from __future__ import print_function
22
import heapq
33
import numpy as np
4-
import math
5-
import copy
64

75
try:
86
xrange # Python 2

Graphs/basic-graphs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def dijk(G, s):
140140

141141

142142
def topo(G, ind=None, Q=[1]):
143-
if ind == None:
143+
if ind is None:
144144
ind = [0] * (len(G) + 1) # SInce oth Index is ignored
145145
for u in G:
146146
for v in G[u]:

Maths/BasicMaths.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,13 @@ def eulerPhi(n):
6262
s *= (x - 1)/x
6363
return s
6464

65-
print(primeFactors(100))
66-
print(numberOfDivisors(100))
67-
print(sumOfDivisors(100))
68-
print(eulerPhi(100))
65+
def main():
66+
print(primeFactors(100))
67+
print(numberOfDivisors(100))
68+
print(sumOfDivisors(100))
69+
print(eulerPhi(100))
70+
71+
if __name__ == '__main__':
72+
main()
6973

7074

Maths/FibonacciSequenceRecursion.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Fibonacci Sequence Using Recursion
2+
3+
def recur_fibo(n):
4+
return n if n <= 1 else (recur_fibo(n-1) + recur_fibo(n-2))
5+
6+
def isPositiveInteger(limit):
7+
return limit >= 0
8+
9+
def main():
10+
limit = int(input("How many terms to include in fibonacci series: "))
11+
if isPositiveInteger(limit):
12+
print(f"The first {limit} terms of the fibonacci series are as follows:")
13+
print([recur_fibo(n) for n in range(limit)])
14+
else:
15+
print("Please enter a positive integer: ")
16+
17+
if __name__ == '__main__':
18+
main()

Maths/GreaterCommonDivisor.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Greater Common Divisor - https://en.wikipedia.org/wiki/Greatest_common_divisor
2+
def gcd(a, b):
3+
return b if a == 0 else gcd(b % a, a)
4+
5+
def main():
6+
try:
7+
nums = input("Enter two Integers separated by comma (,): ").split(',')
8+
num1 = int(nums[0]); num2 = int(nums[1])
9+
except (IndexError, UnboundLocalError, ValueError):
10+
print("Wrong Input")
11+
print(f"gcd({num1}, {num2}) = {gcd(num1, num2)}")
12+
13+
if __name__ == '__main__':
14+
main()
15+

Maths/fibonacciSeries.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

Maths/gcd.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

Neural_Network/perceptron.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, sample, exit, learn_rate=0.01, epoch_number=1000, bias=-1):
2525
self.col_sample = len(sample[0])
2626
self.weight = []
2727

28-
def trannig(self):
28+
def training(self):
2929
for sample in self.sample:
3030
sample.insert(0, self.bias)
3131

@@ -121,4 +121,4 @@ def sign(self, u):
121121
sample = []
122122
for i in range(3):
123123
sample.insert(i, float(input('value: ')))
124-
network.sort(sample)
124+
network.sort(sample)
File renamed without changes.

Project Euler/Problem 9/sol2.py renamed to Project Euler/Problem 09/sol2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
Given N, Check if there exists any Pythagorean triplet for which a+b+c=N
44
Find maximum possible value of product of a,b,c among all such Pythagorean triplets, If there is no such Pythagorean triplet print -1."""
55
#!/bin/python3
6-
import sys
76

87
product=-1
98
d=0

Project Euler/Problem 15/sol1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import print_function
2-
from math import factorial, ceil
2+
from math import factorial
33

44
def lattice_paths(n):
55
n = 2*n #middle entry of odd rows starting at row 3 is the solution for n = 1, 2, 3,...

0 commit comments

Comments
 (0)