mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
pyupgrade --py37-plus **/*.py (#1654)
* pyupgrade --py37-plus **/*.py * fixup! Format Python code with psf/black push
This commit is contained in:
parent
34c808b375
commit
28419cf839
|
@ -1,5 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
In this problem, we want to determine all possible combinations of k
|
In this problem, we want to determine all possible combinations of k
|
||||||
numbers out of 1 ... n. We use backtracking to solve this problem.
|
numbers out of 1 ... n. We use backtracking to solve this problem.
|
||||||
|
|
|
@ -40,7 +40,7 @@ def decrypt(message):
|
||||||
translated = translated + LETTERS[num]
|
translated = translated + LETTERS[num]
|
||||||
else:
|
else:
|
||||||
translated = translated + symbol
|
translated = translated + symbol
|
||||||
print("Decryption using Key #%s: %s" % (key, translated))
|
print(f"Decryption using Key #{key}: {translated}")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
@ -78,7 +78,7 @@ class HillCipher:
|
||||||
req_l = len(self.key_string)
|
req_l = len(self.key_string)
|
||||||
if gcd(det, len(self.key_string)) != 1:
|
if gcd(det, len(self.key_string)) != 1:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"discriminant modular {0} of encryption key({1}) is not co prime w.r.t {2}.\nTry another key.".format(
|
"discriminant modular {} of encryption key({}) is not co prime w.r.t {}.\nTry another key.".format(
|
||||||
req_l, det, req_l
|
req_l, det, req_l
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -101,7 +101,7 @@ def encryptAndWriteToFile(
|
||||||
for i in range(len(encryptedBlocks)):
|
for i in range(len(encryptedBlocks)):
|
||||||
encryptedBlocks[i] = str(encryptedBlocks[i])
|
encryptedBlocks[i] = str(encryptedBlocks[i])
|
||||||
encryptedContent = ",".join(encryptedBlocks)
|
encryptedContent = ",".join(encryptedBlocks)
|
||||||
encryptedContent = "%s_%s_%s" % (len(message), blockSize, encryptedContent)
|
encryptedContent = "{}_{}_{}".format(len(message), blockSize, encryptedContent)
|
||||||
with open(messageFilename, "w") as fo:
|
with open(messageFilename, "w") as fo:
|
||||||
fo.write(encryptedContent)
|
fo.write(encryptedContent)
|
||||||
return encryptedContent
|
return encryptedContent
|
||||||
|
|
|
@ -43,11 +43,11 @@ def makeKeyFiles(name, keySize):
|
||||||
publicKey, privateKey = generateKey(keySize)
|
publicKey, privateKey = generateKey(keySize)
|
||||||
print("\nWriting public key to file %s_pubkey.txt..." % name)
|
print("\nWriting public key to file %s_pubkey.txt..." % name)
|
||||||
with open("%s_pubkey.txt" % name, "w") as fo:
|
with open("%s_pubkey.txt" % name, "w") as fo:
|
||||||
fo.write("%s,%s,%s" % (keySize, publicKey[0], publicKey[1]))
|
fo.write("{},{},{}".format(keySize, publicKey[0], publicKey[1]))
|
||||||
|
|
||||||
print("Writing private key to file %s_privkey.txt..." % name)
|
print("Writing private key to file %s_privkey.txt..." % name)
|
||||||
with open("%s_privkey.txt" % name, "w") as fo:
|
with open("%s_privkey.txt" % name, "w") as fo:
|
||||||
fo.write("%s,%s,%s" % (keySize, privateKey[0], privateKey[1]))
|
fo.write("{},{},{}".format(keySize, privateKey[0], privateKey[1]))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -2,7 +2,7 @@ import random
|
||||||
import string
|
import string
|
||||||
|
|
||||||
|
|
||||||
class ShuffledShiftCipher(object):
|
class ShuffledShiftCipher:
|
||||||
"""
|
"""
|
||||||
This algorithm uses the Caesar Cipher algorithm but removes the option to
|
This algorithm uses the Caesar Cipher algorithm but removes the option to
|
||||||
use brute force to decrypt the message.
|
use brute force to decrypt the message.
|
||||||
|
|
|
@ -17,7 +17,7 @@ def main():
|
||||||
mode = "decrypt"
|
mode = "decrypt"
|
||||||
translated = decryptMessage(key, message)
|
translated = decryptMessage(key, message)
|
||||||
|
|
||||||
print("\n%sion: \n%s" % (mode.title(), translated))
|
print("\n{}ion: \n{}".format(mode.title(), translated))
|
||||||
|
|
||||||
|
|
||||||
def checkValidKey(key):
|
def checkValidKey(key):
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class XORCipher(object):
|
class XORCipher:
|
||||||
def __init__(self, key=0):
|
def __init__(self, key=0):
|
||||||
"""
|
"""
|
||||||
simple constructor that receives a key or uses
|
simple constructor that receives a key or uses
|
||||||
|
|
|
@ -135,16 +135,14 @@ def reverse_bwt(bwt_string: str, idx_original_string: int) -> str:
|
||||||
idx_original_string = int(idx_original_string)
|
idx_original_string = int(idx_original_string)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
(
|
|
||||||
"The parameter idx_original_string type must be int or passive"
|
"The parameter idx_original_string type must be int or passive"
|
||||||
" of cast to int."
|
" of cast to int."
|
||||||
)
|
)
|
||||||
)
|
|
||||||
if idx_original_string < 0:
|
if idx_original_string < 0:
|
||||||
raise ValueError("The parameter idx_original_string must not be lower than 0.")
|
raise ValueError("The parameter idx_original_string must not be lower than 0.")
|
||||||
if idx_original_string >= len(bwt_string):
|
if idx_original_string >= len(bwt_string):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
("The parameter idx_original_string must be lower than" " len(bwt_string).")
|
"The parameter idx_original_string must be lower than" " len(bwt_string)."
|
||||||
)
|
)
|
||||||
|
|
||||||
ordered_rotations = [""] * len(bwt_string)
|
ordered_rotations = [""] * len(bwt_string)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
An auto-balanced binary tree!
|
An auto-balanced binary tree!
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -467,7 +467,7 @@ class RedBlackTree:
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
|
|
||||||
if self.left is None and self.right is None:
|
if self.left is None and self.right is None:
|
||||||
return "'%s %s'" % (self.label, (self.color and "red") or "blk")
|
return "'{} {}'".format(self.label, (self.color and "red") or "blk")
|
||||||
return pformat(
|
return pformat(
|
||||||
{
|
{
|
||||||
"%s %s"
|
"%s %s"
|
||||||
|
|
|
@ -2,7 +2,7 @@ from random import random
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
|
|
||||||
class Node(object):
|
class Node:
|
||||||
"""
|
"""
|
||||||
Treap's node
|
Treap's node
|
||||||
Treap is a binary tree by value and heap by priority
|
Treap is a binary tree by value and heap by priority
|
||||||
|
@ -18,11 +18,10 @@ class Node(object):
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
|
|
||||||
if self.left is None and self.right is None:
|
if self.left is None and self.right is None:
|
||||||
return "'%s: %.5s'" % (self.value, self.prior)
|
return f"'{self.value}: {self.prior:.5}'"
|
||||||
else:
|
else:
|
||||||
return pformat(
|
return pformat(
|
||||||
{"%s: %.5s" % (self.value, self.prior): (self.left, self.right)},
|
{f"{self.value}: {self.prior:.5}": (self.left, self.right)}, indent=1,
|
||||||
indent=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class Heap(object):
|
class Heap:
|
||||||
"""A generic Heap class, can be used as min or max by passing the key function accordingly.
|
"""A generic Heap class, can be used as min or max by passing the key function accordingly.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ class HashTable:
|
||||||
|
|
||||||
def _step_by_step(self, step_ord):
|
def _step_by_step(self, step_ord):
|
||||||
|
|
||||||
print("step {0}".format(step_ord))
|
print(f"step {step_ord}")
|
||||||
print([i for i in range(len(self.values))])
|
print([i for i in range(len(self.values))])
|
||||||
print(self.values)
|
print(self.values)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
__author__ = "Omkar Pathak"
|
__author__ = "Omkar Pathak"
|
||||||
|
|
||||||
|
|
||||||
class Stack(object):
|
class Stack:
|
||||||
""" A stack is an abstract data type that serves as a collection of
|
""" A stack is an abstract data type that serves as a collection of
|
||||||
elements with two principal operations: push() and pop(). push() adds an
|
elements with two principal operations: push() and pop(). push() adds an
|
||||||
element to the top of the stack, and pop() removes an element from the top
|
element to the top of the stack, and pop() removes an element from the top
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
Created on Fri Sep 28 15:22:29 2018
|
Created on Fri Sep 28 15:22:29 2018
|
||||||
|
|
||||||
|
|
|
@ -389,10 +389,7 @@ class IndexCalculation:
|
||||||
:return: index
|
:return: index
|
||||||
"""
|
"""
|
||||||
return np.arctan(
|
return np.arctan(
|
||||||
(
|
((2 * self.red - self.green - self.blue) / 30.5) * (self.green - self.blue)
|
||||||
((2 * self.red - self.green - self.blue) / 30.5)
|
|
||||||
* (self.green - self.blue)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def IVI(self, a=None, b=None):
|
def IVI(self, a=None, b=None):
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# encoding=utf8
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This program calculates the nth Fibonacci number in O(log(n)).
|
This program calculates the nth Fibonacci number in O(log(n)).
|
||||||
|
|
|
@ -40,7 +40,7 @@ def TFKMeansCluster(vectors, noofclusters):
|
||||||
##First lets ensure we have a Variable vector for each centroid,
|
##First lets ensure we have a Variable vector for each centroid,
|
||||||
##initialized to one of the vectors from the available data points
|
##initialized to one of the vectors from the available data points
|
||||||
centroids = [
|
centroids = [
|
||||||
tf.Variable((vectors[vector_indices[i]])) for i in range(noofclusters)
|
tf.Variable(vectors[vector_indices[i]]) for i in range(noofclusters)
|
||||||
]
|
]
|
||||||
##These nodes will assign the centroid Variables the appropriate
|
##These nodes will assign the centroid Variables the appropriate
|
||||||
##values
|
##values
|
||||||
|
|
|
@ -46,7 +46,7 @@ def main():
|
||||||
# 30*35 35*15 15*5 5*10 10*20 20*25
|
# 30*35 35*15 15*5 5*10 10*20 20*25
|
||||||
Matrix, OptimalSolution = MatrixChainOrder(array)
|
Matrix, OptimalSolution = MatrixChainOrder(array)
|
||||||
|
|
||||||
print("No. of Operation required: " + str((Matrix[1][n - 1])))
|
print("No. of Operation required: " + str(Matrix[1][n - 1]))
|
||||||
PrintOptimalSolution(OptimalSolution, 1, n - 1)
|
PrintOptimalSolution(OptimalSolution, 1, n - 1)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
|
|
||||||
def dfs(G, s):
|
def dfs(G, s):
|
||||||
vis, S = set([s]), [s]
|
vis, S = {s}, [s]
|
||||||
print(s)
|
print(s)
|
||||||
while S:
|
while S:
|
||||||
flag = 0
|
flag = 0
|
||||||
|
@ -76,7 +76,7 @@ from collections import deque
|
||||||
|
|
||||||
|
|
||||||
def bfs(G, s):
|
def bfs(G, s):
|
||||||
vis, Q = set([s]), deque([s])
|
vis, Q = {s}, deque([s])
|
||||||
print(s)
|
print(s)
|
||||||
while Q:
|
while Q:
|
||||||
u = Q.popleft()
|
u = Q.popleft()
|
||||||
|
@ -255,7 +255,7 @@ def krusk(E_and_n):
|
||||||
# Sort edges on the basis of distance
|
# Sort edges on the basis of distance
|
||||||
(E, n) = E_and_n
|
(E, n) = E_and_n
|
||||||
E.sort(reverse=True, key=lambda x: x[2])
|
E.sort(reverse=True, key=lambda x: x[2])
|
||||||
s = [set([i]) for i in range(1, n + 1)]
|
s = [{i} for i in range(1, n + 1)]
|
||||||
while True:
|
while True:
|
||||||
if len(s) == 1:
|
if len(s) == 1:
|
||||||
break
|
break
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# encoding=utf8
|
|
||||||
|
|
||||||
""" Author: OMKAR PATHAK """
|
""" Author: OMKAR PATHAK """
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# encoding=utf8
|
|
||||||
|
|
||||||
""" Author: OMKAR PATHAK """
|
""" Author: OMKAR PATHAK """
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ class FlowNetwork:
|
||||||
self.maximumFlowAlgorithm = Algorithm(self)
|
self.maximumFlowAlgorithm = Algorithm(self)
|
||||||
|
|
||||||
|
|
||||||
class FlowNetworkAlgorithmExecutor(object):
|
class FlowNetworkAlgorithmExecutor:
|
||||||
def __init__(self, flowNetwork):
|
def __init__(self, flowNetwork):
|
||||||
self.flowNetwork = flowNetwork
|
self.flowNetwork = flowNetwork
|
||||||
self.verticesCount = flowNetwork.verticesCount
|
self.verticesCount = flowNetwork.verticesCount
|
||||||
|
@ -80,7 +80,7 @@ class FlowNetworkAlgorithmExecutor(object):
|
||||||
|
|
||||||
class MaximumFlowAlgorithmExecutor(FlowNetworkAlgorithmExecutor):
|
class MaximumFlowAlgorithmExecutor(FlowNetworkAlgorithmExecutor):
|
||||||
def __init__(self, flowNetwork):
|
def __init__(self, flowNetwork):
|
||||||
super(MaximumFlowAlgorithmExecutor, self).__init__(flowNetwork)
|
super().__init__(flowNetwork)
|
||||||
# use this to save your result
|
# use this to save your result
|
||||||
self.maximumFlow = -1
|
self.maximumFlow = -1
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ class MaximumFlowAlgorithmExecutor(FlowNetworkAlgorithmExecutor):
|
||||||
|
|
||||||
class PushRelabelExecutor(MaximumFlowAlgorithmExecutor):
|
class PushRelabelExecutor(MaximumFlowAlgorithmExecutor):
|
||||||
def __init__(self, flowNetwork):
|
def __init__(self, flowNetwork):
|
||||||
super(PushRelabelExecutor, self).__init__(flowNetwork)
|
super().__init__(flowNetwork)
|
||||||
|
|
||||||
self.preflow = [[0] * self.verticesCount for i in range(self.verticesCount)]
|
self.preflow = [[0] * self.verticesCount for i in range(self.verticesCount)]
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# encoding=utf8
|
|
||||||
|
|
||||||
# Author: OMKAR PATHAK
|
# Author: OMKAR PATHAK
|
||||||
|
|
||||||
# We can use Python's dictionary for constructing the graph.
|
# We can use Python's dictionary for constructing the graph.
|
||||||
|
|
||||||
|
|
||||||
class AdjacencyList(object):
|
class AdjacencyList:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.List = {}
|
self.List = {}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Author: João Gustavo A. Amorim & Gabriel Kunz
|
# Author: João Gustavo A. Amorim & Gabriel Kunz
|
||||||
# Author email: joaogustavoamorim@gmail.com and gabriel-kunz@uergs.edu.br
|
# Author email: joaogustavoamorim@gmail.com and gabriel-kunz@uergs.edu.br
|
||||||
# Coding date: apr 2019
|
# Coding date: apr 2019
|
||||||
|
@ -100,7 +99,7 @@ def emitterConverter(sizePar, data):
|
||||||
# Performs a template of bit positions - who should be given,
|
# Performs a template of bit positions - who should be given,
|
||||||
# and who should be parity
|
# and who should be parity
|
||||||
if qtdBP < sizePar:
|
if qtdBP < sizePar:
|
||||||
if ((np.log(x) / np.log(2))).is_integer():
|
if (np.log(x) / np.log(2)).is_integer():
|
||||||
dataOutGab.append("P")
|
dataOutGab.append("P")
|
||||||
qtdBP = qtdBP + 1
|
qtdBP = qtdBP + 1
|
||||||
else:
|
else:
|
||||||
|
@ -170,7 +169,7 @@ def receptorConverter(sizePar, data):
|
||||||
# Performs a template of bit positions - who should be given,
|
# Performs a template of bit positions - who should be given,
|
||||||
# and who should be parity
|
# and who should be parity
|
||||||
if qtdBP < sizePar:
|
if qtdBP < sizePar:
|
||||||
if ((np.log(x) / np.log(2))).is_integer():
|
if (np.log(x) / np.log(2)).is_integer():
|
||||||
dataOutGab.append("P")
|
dataOutGab.append("P")
|
||||||
qtdBP = qtdBP + 1
|
qtdBP = qtdBP + 1
|
||||||
else:
|
else:
|
||||||
|
@ -204,7 +203,7 @@ def receptorConverter(sizePar, data):
|
||||||
# Performs a template position of bits - who should be given,
|
# Performs a template position of bits - who should be given,
|
||||||
# and who should be parity
|
# and who should be parity
|
||||||
if qtdBP < sizePar:
|
if qtdBP < sizePar:
|
||||||
if ((np.log(x) / np.log(2))).is_integer():
|
if (np.log(x) / np.log(2)).is_integer():
|
||||||
dataOutGab.append("P")
|
dataOutGab.append("P")
|
||||||
qtdBP = qtdBP + 1
|
qtdBP = qtdBP + 1
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
Created on Mon Feb 26 14:29:11 2018
|
Created on Mon Feb 26 14:29:11 2018
|
||||||
|
|
||||||
|
@ -25,7 +24,7 @@ import math
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
|
||||||
class Vector(object):
|
class Vector:
|
||||||
"""
|
"""
|
||||||
This class represents a vector of arbitrary size.
|
This class represents a vector of arbitrary size.
|
||||||
You need to give the vector components.
|
You need to give the vector components.
|
||||||
|
@ -205,7 +204,7 @@ def randomVector(N, a, b):
|
||||||
return Vector(ans)
|
return Vector(ans)
|
||||||
|
|
||||||
|
|
||||||
class Matrix(object):
|
class Matrix:
|
||||||
"""
|
"""
|
||||||
class: Matrix
|
class: Matrix
|
||||||
This class represents a arbitrary matrix.
|
This class represents a arbitrary matrix.
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
Created on Mon Feb 26 15:40:07 2018
|
Created on Mon Feb 26 15:40:07 2018
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ def plot_heterogeneity(heterogeneity, k):
|
||||||
plt.plot(heterogeneity, linewidth=4)
|
plt.plot(heterogeneity, linewidth=4)
|
||||||
plt.xlabel("# Iterations")
|
plt.xlabel("# Iterations")
|
||||||
plt.ylabel("Heterogeneity")
|
plt.ylabel("Heterogeneity")
|
||||||
plt.title("Heterogeneity of clustering over time, K={0:d}".format(k))
|
plt.title(f"Heterogeneity of clustering over time, K={k:d}")
|
||||||
plt.rcParams.update({"font.size": 16})
|
plt.rcParams.update({"font.size": 16})
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ def kmeans(
|
||||||
num_changed = np.sum(prev_cluster_assignment != cluster_assignment)
|
num_changed = np.sum(prev_cluster_assignment != cluster_assignment)
|
||||||
if verbose:
|
if verbose:
|
||||||
print(
|
print(
|
||||||
" {0:5d} elements changed their cluster assignment.".format(
|
" {:5d} elements changed their cluster assignment.".format(
|
||||||
num_changed
|
num_changed
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
## Logistic Regression from scratch
|
## Logistic Regression from scratch
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# coding: utf-8
|
|
||||||
"""
|
"""
|
||||||
Implementation of sequential minimal optimization(SMO) for support vector machines(SVM).
|
Implementation of sequential minimal optimization(SMO) for support vector machines(SVM).
|
||||||
|
|
||||||
|
@ -29,7 +28,6 @@ Reference:
|
||||||
http://web.cs.iastate.edu/~honavar/smo-svm.pdf
|
http://web.cs.iastate.edu/~honavar/smo-svm.pdf
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import division
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -44,7 +42,7 @@ from sklearn.preprocessing import StandardScaler
|
||||||
CANCER_DATASET_URL = "http://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/wdbc.data"
|
CANCER_DATASET_URL = "http://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/wdbc.data"
|
||||||
|
|
||||||
|
|
||||||
class SmoSVM(object):
|
class SmoSVM:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
train,
|
train,
|
||||||
|
@ -405,7 +403,7 @@ class SmoSVM(object):
|
||||||
return self.samples.shape[0]
|
return self.samples.shape[0]
|
||||||
|
|
||||||
|
|
||||||
class Kernel(object):
|
class Kernel:
|
||||||
def __init__(self, kernel, degree=1.0, coef0=0.0, gamma=1.0):
|
def __init__(self, kernel, degree=1.0, coef0=0.0, gamma=1.0):
|
||||||
self.degree = np.float64(degree)
|
self.degree = np.float64(degree)
|
||||||
self.coef0 = np.float64(coef0)
|
self.coef0 = np.float64(coef0)
|
||||||
|
|
|
@ -9,9 +9,9 @@ def n31(a: int) -> Tuple[List[int], int]:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not isinstance(a, int):
|
if not isinstance(a, int):
|
||||||
raise TypeError("Must be int, not {0}".format(type(a).__name__))
|
raise TypeError("Must be int, not {}".format(type(a).__name__))
|
||||||
if a < 1:
|
if a < 1:
|
||||||
raise ValueError("Given integer must be greater than 1, not {0}".format(a))
|
raise ValueError(f"Given integer must be greater than 1, not {a}")
|
||||||
|
|
||||||
path = [a]
|
path = [a]
|
||||||
while a != 1:
|
while a != 1:
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
|
|
|
@ -37,7 +37,7 @@ def exactPrimeFactorCount(n):
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
n = 51242183
|
n = 51242183
|
||||||
print(f"The number of distinct prime factors is/are {exactPrimeFactorCount(n)}")
|
print(f"The number of distinct prime factors is/are {exactPrimeFactorCount(n)}")
|
||||||
print("The value of log(log(n)) is {0:.4f}".format(math.log(math.log(n))))
|
print("The value of log(log(n)) is {:.4f}".format(math.log(math.log(n))))
|
||||||
|
|
||||||
"""
|
"""
|
||||||
The number of distinct prime factors is/are 3
|
The number of distinct prime factors is/are 3
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
In mathematics, the Lucas–Lehmer test (LLT) is a primality test for Mersenne numbers.
|
In mathematics, the Lucas–Lehmer test (LLT) is a primality test for Mersenne numbers.
|
||||||
https://en.wikipedia.org/wiki/Lucas%E2%80%93Lehmer_primality_test
|
https://en.wikipedia.org/wiki/Lucas%E2%80%93Lehmer_primality_test
|
||||||
|
|
|
@ -10,7 +10,7 @@ https://www.hackerearth.com/practice/notes/matrix-exponentiation-1/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class Matrix(object):
|
class Matrix:
|
||||||
def __init__(self, arg):
|
def __init__(self, arg):
|
||||||
if isinstance(arg, list): # Initialzes a matrix identical to the one provided.
|
if isinstance(arg, list): # Initialzes a matrix identical to the one provided.
|
||||||
self.t = arg
|
self.t = arg
|
||||||
|
|
|
@ -52,4 +52,4 @@ if __name__ == "__main__":
|
||||||
plt.xlabel("step")
|
plt.xlabel("step")
|
||||||
plt.ylabel("error")
|
plt.ylabel("error")
|
||||||
plt.show()
|
plt.show()
|
||||||
print("solution = {%f}, error = {%f}" % (solution, error))
|
print(f"solution = {{{solution:f}}}, error = {{{error:f}}}")
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Point:
|
||||||
|
|
||||||
|
|
||||||
def distance(a: Point, b: Point) -> float:
|
def distance(a: Point, b: Point) -> float:
|
||||||
return math.sqrt(abs(((b.x - a.x) ** 2 + (b.y - a.y) ** 2 + (b.z - a.z) ** 2)))
|
return math.sqrt(abs((b.x - a.x) ** 2 + (b.y - a.y) ** 2 + (b.z - a.z) ** 2))
|
||||||
|
|
||||||
|
|
||||||
def test_distance() -> None:
|
def test_distance() -> None:
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Sieve of Eratosthones
|
Sieve of Eratosthones
|
||||||
|
|
||||||
|
|
|
@ -148,9 +148,9 @@ def main():
|
||||||
% (matrix_a, matrix_b, multiply(matrix_a, matrix_b))
|
% (matrix_a, matrix_b, multiply(matrix_a, matrix_b))
|
||||||
)
|
)
|
||||||
print("Identity: %s \n" % identity(5))
|
print("Identity: %s \n" % identity(5))
|
||||||
print("Minor of %s = %s \n" % (matrix_c, minor(matrix_c, 1, 2)))
|
print("Minor of {} = {} \n".format(matrix_c, minor(matrix_c, 1, 2)))
|
||||||
print("Determinant of %s = %s \n" % (matrix_b, determinant(matrix_b)))
|
print("Determinant of {} = {} \n".format(matrix_b, determinant(matrix_b)))
|
||||||
print("Inverse of %s = %s\n" % (matrix_d, inverse(matrix_d)))
|
print("Inverse of {} = {}\n".format(matrix_d, inverse(matrix_d)))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
In this problem, we want to rotate the matrix elements by 90, 180, 270 (counterclockwise)
|
In this problem, we want to rotate the matrix elements by 90, 180, 270 (counterclockwise)
|
||||||
Discussion in stackoverflow:
|
Discussion in stackoverflow:
|
||||||
|
|
|
@ -2,7 +2,7 @@ def search_in_a_sorted_matrix(mat, m, n, key):
|
||||||
i, j = m - 1, 0
|
i, j = m - 1, 0
|
||||||
while i >= 0 and j < n:
|
while i >= 0 and j < n:
|
||||||
if key == mat[i][j]:
|
if key == mat[i][j]:
|
||||||
print("Key %s found at row- %s column- %s" % (key, i + 1, j + 1))
|
print("Key {} found at row- {} column- {}".format(key, i + 1, j + 1))
|
||||||
return
|
return
|
||||||
if key < mat[i][j]:
|
if key < mat[i][j]:
|
||||||
i -= 1
|
i -= 1
|
||||||
|
|
|
@ -176,7 +176,7 @@ class Matrix:
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
"Unsupported type given for another (%s)" % (type(another),)
|
"Unsupported type given for another ({})".format(type(another))
|
||||||
)
|
)
|
||||||
|
|
||||||
def transpose(self):
|
def transpose(self):
|
||||||
|
@ -248,17 +248,17 @@ if __name__ == "__main__":
|
||||||
ainv = Matrix(3, 3, 0)
|
ainv = Matrix(3, 3, 0)
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
ainv[i, i] = 1
|
ainv[i, i] = 1
|
||||||
print("a^(-1) is %s" % (ainv,))
|
print(f"a^(-1) is {ainv}")
|
||||||
# u, v
|
# u, v
|
||||||
u = Matrix(3, 1, 0)
|
u = Matrix(3, 1, 0)
|
||||||
u[0, 0], u[1, 0], u[2, 0] = 1, 2, -3
|
u[0, 0], u[1, 0], u[2, 0] = 1, 2, -3
|
||||||
v = Matrix(3, 1, 0)
|
v = Matrix(3, 1, 0)
|
||||||
v[0, 0], v[1, 0], v[2, 0] = 4, -2, 5
|
v[0, 0], v[1, 0], v[2, 0] = 4, -2, 5
|
||||||
print("u is %s" % (u,))
|
print(f"u is {u}")
|
||||||
print("v is %s" % (v,))
|
print(f"v is {v}")
|
||||||
print("uv^T is %s" % (u * v.transpose()))
|
print("uv^T is %s" % (u * v.transpose()))
|
||||||
# Sherman Morrison
|
# Sherman Morrison
|
||||||
print("(a + uv^T)^(-1) is %s" % (ainv.ShermanMorrison(u, v),))
|
print("(a + uv^T)^(-1) is {}".format(ainv.ShermanMorrison(u, v)))
|
||||||
|
|
||||||
def test2():
|
def test2():
|
||||||
import doctest
|
import doctest
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# encoding=utf8
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -31,6 +30,7 @@ class DenseLayer:
|
||||||
"""
|
"""
|
||||||
Layers of BP neural network
|
Layers of BP neural network
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, units, activation=None, learning_rate=None, is_input_layer=False
|
self, units, activation=None, learning_rate=None, is_input_layer=False
|
||||||
):
|
):
|
||||||
|
@ -99,6 +99,7 @@ class BPNN:
|
||||||
"""
|
"""
|
||||||
Back Propagation Neural Network model
|
Back Propagation Neural Network model
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.layers = []
|
self.layers = []
|
||||||
self.train_mse = []
|
self.train_mse = []
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
- - - - - -- - - - - - - - - - - - - - - - - - - - - - -
|
- - - - - -- - - - - - - - - - - - - - - - - - - - - - -
|
||||||
Name - - CNN - Convolution Neural Network For Photo Recognizing
|
Name - - CNN - Convolution Neural Network For Photo Recognizing
|
||||||
|
@ -286,7 +284,7 @@ class CNN:
|
||||||
self.thre_bp3 = self.thre_bp3 - pd_k_all * self.rate_thre
|
self.thre_bp3 = self.thre_bp3 - pd_k_all * self.rate_thre
|
||||||
self.thre_bp2 = self.thre_bp2 - pd_j_all * self.rate_thre
|
self.thre_bp2 = self.thre_bp2 - pd_j_all * self.rate_thre
|
||||||
# calculate the sum error of all single image
|
# calculate the sum error of all single image
|
||||||
errors = np.sum(abs((data_teach - bp_out3)))
|
errors = np.sum(abs(data_teach - bp_out3))
|
||||||
alle = alle + errors
|
alle = alle + errors
|
||||||
# print(' ----Teach ',data_teach)
|
# print(' ----Teach ',data_teach)
|
||||||
# print(' ----BP_output ',bp_out3)
|
# print(' ----BP_output ',bp_out3)
|
||||||
|
|
|
@ -17,9 +17,6 @@
|
||||||
This module and all its submodules are deprecated.
|
This module and all its submodules are deprecated.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import division
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
import gzip
|
import gzip
|
||||||
|
@ -115,7 +112,7 @@ def _extract_labels(f, one_hot=False, num_classes=10):
|
||||||
return labels
|
return labels
|
||||||
|
|
||||||
|
|
||||||
class _DataSet(object):
|
class _DataSet:
|
||||||
"""Container class for a _DataSet (deprecated).
|
"""Container class for a _DataSet (deprecated).
|
||||||
|
|
||||||
THIS CLASS IS DEPRECATED.
|
THIS CLASS IS DEPRECATED.
|
||||||
|
@ -165,7 +162,7 @@ class _DataSet(object):
|
||||||
else:
|
else:
|
||||||
assert (
|
assert (
|
||||||
images.shape[0] == labels.shape[0]
|
images.shape[0] == labels.shape[0]
|
||||||
), "images.shape: %s labels.shape: %s" % (images.shape, labels.shape)
|
), f"images.shape: {images.shape} labels.shape: {labels.shape}"
|
||||||
self._num_examples = images.shape[0]
|
self._num_examples = images.shape[0]
|
||||||
|
|
||||||
# Convert shape from [num examples, rows, columns, depth]
|
# Convert shape from [num examples, rows, columns, depth]
|
||||||
|
|
|
@ -4,7 +4,7 @@ start_time = time.time()
|
||||||
print("creating word list...")
|
print("creating word list...")
|
||||||
path = os.path.split(os.path.realpath(__file__))
|
path = os.path.split(os.path.realpath(__file__))
|
||||||
with open(path[0] + "/words") as f:
|
with open(path[0] + "/words") as f:
|
||||||
word_list = sorted(list(set([word.strip().lower() for word in f])))
|
word_list = sorted(list({word.strip().lower() for word in f}))
|
||||||
|
|
||||||
|
|
||||||
def signature(word):
|
def signature(word):
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# encoding=utf8
|
|
||||||
"""
|
"""
|
||||||
The Fisher–Yates shuffle is an algorithm for generating a random permutation of a finite sequence.
|
The Fisher–Yates shuffle is an algorithm for generating a random permutation of a finite sequence.
|
||||||
For more details visit
|
For more details visit
|
||||||
|
|
|
@ -3,7 +3,7 @@ __author__ = "Tobias Carryer"
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
|
|
||||||
class LinearCongruentialGenerator(object):
|
class LinearCongruentialGenerator:
|
||||||
"""
|
"""
|
||||||
A pseudorandom number generator.
|
A pseudorandom number generator.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
Created on Thu Oct 5 16:44:23 2017
|
Created on Thu Oct 5 16:44:23 2017
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# encoding=utf8
|
|
||||||
|
|
||||||
"""Author Anurag Kumar | anuragkumarak95@gmail.com | git/anuragkumarak95
|
"""Author Anurag Kumar | anuragkumarak95@gmail.com | git/anuragkumarak95
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
Problem:
|
Problem:
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
Problem:
|
Problem:
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
Problem:
|
Problem:
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
Problem:
|
Problem:
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
By listing the first six prime numbers:
|
By listing the first six prime numbers:
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
By listing the first six prime numbers:
|
By listing the first six prime numbers:
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
By listing the first six prime numbers:
|
By listing the first six prime numbers:
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
The four adjacent digits in the 1000-digit number that have the greatest
|
The four adjacent digits in the 1000-digit number that have the greatest
|
||||||
product are 9 × 9 × 8 × 9 = 5832.
|
product are 9 × 9 × 8 × 9 = 5832.
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
The four adjacent digits in the 1000-digit number that have the greatest
|
The four adjacent digits in the 1000-digit number that have the greatest
|
||||||
product are 9 × 9 × 8 × 9 = 5832.
|
product are 9 × 9 × 8 × 9 = 5832.
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
The four adjacent digits in the 1000-digit number that have the greatest
|
The four adjacent digits in the 1000-digit number that have the greatest
|
||||||
product are 9 × 9 × 8 × 9 = 5832.
|
product are 9 × 9 × 8 × 9 = 5832.
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
Problem Statement:
|
Problem Statement:
|
||||||
The following iterative sequence is defined for the set of positive integers:
|
The following iterative sequence is defined for the set of positive integers:
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
Collatz conjecture: start with any positive integer n. Next term obtained from
|
Collatz conjecture: start with any positive integer n. Next term obtained from
|
||||||
the previous term as follows:
|
the previous term as follows:
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -.- coding: latin-1 -.-
|
|
||||||
from math import sqrt
|
from math import sqrt
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: latin-1 -*-
|
|
||||||
"""
|
"""
|
||||||
Name scores
|
Name scores
|
||||||
Problem 22
|
Problem 22
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: latin-1 -*-
|
|
||||||
"""
|
"""
|
||||||
Name scores
|
Name scores
|
||||||
Problem 22
|
Problem 22
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
The Fibonacci sequence is defined by the recurrence relation:
|
The Fibonacci sequence is defined by the recurrence relation:
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
The Fibonacci sequence is defined by the recurrence relation:
|
The Fibonacci sequence is defined by the recurrence relation:
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
The Fibonacci sequence is defined by the recurrence relation:
|
The Fibonacci sequence is defined by the recurrence relation:
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
Coin sums
|
Coin sums
|
||||||
Problem 31
|
Problem 31
|
||||||
|
|
|
@ -46,13 +46,11 @@ def solution():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return sum(
|
return sum(
|
||||||
set(
|
{
|
||||||
[
|
|
||||||
int("".join(pandigital[5:9]))
|
int("".join(pandigital[5:9]))
|
||||||
for pandigital in itertools.permutations("123456789")
|
for pandigital in itertools.permutations("123456789")
|
||||||
if isCombinationValid(pandigital)
|
if isCombinationValid(pandigital)
|
||||||
]
|
}
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
|
|
|
@ -43,7 +43,7 @@ def solve(digit_len: int) -> str:
|
||||||
while den <= 99:
|
while den <= 99:
|
||||||
if (num != den) and (num % 10 == den // 10) and (den % 10 != 0):
|
if (num != den) and (num % 10 == den // 10) and (den % 10 != 0):
|
||||||
if isDigitCancelling(num, den):
|
if isDigitCancelling(num, den):
|
||||||
solutions.append("{}/{}".format(num, den))
|
solutions.append(f"{num}/{den}")
|
||||||
den += 1
|
den += 1
|
||||||
num += 1
|
num += 1
|
||||||
den = 10
|
den = 10
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -.- coding: latin-1 -.-
|
|
||||||
"""
|
"""
|
||||||
Champernowne's constant
|
Champernowne's constant
|
||||||
Problem 40
|
Problem 40
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -.- coding: latin-1 -.-
|
|
||||||
"""
|
"""
|
||||||
Combinatoric selections
|
Combinatoric selections
|
||||||
Problem 53
|
Problem 53
|
||||||
|
|
|
@ -7,7 +7,7 @@ import os
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
class FileSplitter(object):
|
class FileSplitter:
|
||||||
BLOCK_FILENAME_FORMAT = "block_{0}.dat"
|
BLOCK_FILENAME_FORMAT = "block_{0}.dat"
|
||||||
|
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
|
@ -44,7 +44,7 @@ class FileSplitter(object):
|
||||||
map(lambda f: os.remove(f), self.block_filenames)
|
map(lambda f: os.remove(f), self.block_filenames)
|
||||||
|
|
||||||
|
|
||||||
class NWayMerge(object):
|
class NWayMerge:
|
||||||
def select(self, choices):
|
def select(self, choices):
|
||||||
min_index = -1
|
min_index = -1
|
||||||
min_str = None
|
min_str = None
|
||||||
|
@ -56,7 +56,7 @@ class NWayMerge(object):
|
||||||
return min_index
|
return min_index
|
||||||
|
|
||||||
|
|
||||||
class FilesArray(object):
|
class FilesArray:
|
||||||
def __init__(self, files):
|
def __init__(self, files):
|
||||||
self.files = files
|
self.files = files
|
||||||
self.empty = set()
|
self.empty = set()
|
||||||
|
@ -89,7 +89,7 @@ class FilesArray(object):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
class FileMerger(object):
|
class FileMerger:
|
||||||
def __init__(self, merge_strategy):
|
def __init__(self, merge_strategy):
|
||||||
self.merge_strategy = merge_strategy
|
self.merge_strategy = merge_strategy
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ class FileMerger(object):
|
||||||
return files
|
return files
|
||||||
|
|
||||||
|
|
||||||
class ExternalSort(object):
|
class ExternalSort:
|
||||||
def __init__(self, block_size):
|
def __init__(self, block_size):
|
||||||
self.block_size = block_size
|
self.block_size = block_size
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ class Automaton:
|
||||||
for key in self.adlist[current_state]["output"]:
|
for key in self.adlist[current_state]["output"]:
|
||||||
if not (key in result):
|
if not (key in result):
|
||||||
result[key] = []
|
result[key] = []
|
||||||
result[key].append((i - len(key) + 1))
|
result[key].append(i - len(key) + 1)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user