diff --git a/README.md b/README.md index 89f3b2d..80c88a5 100644 --- a/README.md +++ b/README.md @@ -74,8 +74,8 @@ Some pictures and ideas are from `<>` * [isBipartGraph.py](./graph/isBipartGraph.py) * [math](./math) * [README.md](./math/README.md) + * [dft.py](./math/dft.py) * [fastPow.py](./math/fastPow.py) - * [fft.py](./math/fft.py) * [fibonacci](./math/fibonacci) * [numWeight](./math/numWeight) * [numberTheory](./math/numberTheory) diff --git a/math/fft.py b/math/dft.py similarity index 100% rename from math/fft.py rename to math/dft.py diff --git a/math/permute/permute_back_track.py b/math/permute/permute_back_track.py index 84d6c15..89934e2 100644 --- a/math/permute/permute_back_track.py +++ b/math/permute/permute_back_track.py @@ -9,15 +9,19 @@ # Description: ######################################################################### ''' -def permute(n): - def _util(lst,i): - if i==n:print(lst) - else: - for j in range(i,n): - lst[i],lst[j]=lst[j],lst[i] - _util(lst,i+1) - lst[i],lst[j]=lst[j],lst[i] - _util([i for i in range(n)],0) -if __name__=='__main__': + +def permute(n): + def _util(lst, i): + if i == n: + print(lst) + else: + for j in range(i, n): + lst[i], lst[j] = lst[j], lst[i] + _util(lst, i+1) + lst[i], lst[j] = lst[j], lst[i] + _util([i for i in range(n)], 0) + + +if __name__ == '__main__': permute(5) diff --git a/math/permute/permute_divide_and_conquer.py b/math/permute/permute_divide_and_conquer.py index 922f04c..e90f624 100644 --- a/math/permute/permute_divide_and_conquer.py +++ b/math/permute/permute_divide_and_conquer.py @@ -9,15 +9,19 @@ # Description: ######################################################################### ''' -def permute(lst,n): + + +def permute(lst, n): ''' O(n!), optimal''' - if n==1:print(lst) + if n == 1: + print(lst) else: for i in range(n): - lst[i],lst[n-1] = lst[n-1],lst[i] - permute(lst,n-1) - lst[i],lst[n-1] = lst[n-1],lst[i] + lst[i], lst[n-1] = lst[n-1], lst[i] + permute(lst, n-1) + lst[i], lst[n-1] = lst[n-1], lst[i] -if __name__=='__main__': + +if __name__ == '__main__': n = 3 - permute([i for i in range(n)],n) + permute([i for i in range(n)], n) diff --git a/poly.c b/poly.c new file mode 100644 index 0000000..e69de29