def test(self): self.assertEqual(number([[10, 0], [3, 5], [5, 8]]), 5) self.assertEqual( number([[3, 0], [9, 1], [4, 10], [12, 2], [6, 1], [7, 10]]), 17) self.assertEqual( number([[3, 0], [9, 1], [4, 8], [12, 2], [6, 1], [7, 8]]), 21) self.assertEqual(number([[0, 0]]), 0)
def test(self): self.assertEqual(number([]), []) self.assertEqual(number(["a", "b", "c"]), ["1: a", "2: b", "3: c"]) self.assertEqual(number(["", "", "", "", ""]), ["1: ", "2: ", "3: ", "4: ", "5: "]) self.assertEqual(number(["", "b", "", "", ""]), ["1: ", "2: b", "3: ", "4: ", "5: "])
def test_rand(self): from random import randint for _ in range(100): n = randint(0, 100) arr = [[n, 0]] for _ in range(randint(0, 100)): x, y = randint(0, 100), randint(0, n) arr.append([x, y]) n += x - y self.assertEqual(number(arr), n)
def main(ur, exts, dir, num): url, filetypes, directory, numb = ur.get(), exts.get(), dir.get(), num.get( ) Bowser.open(url) extensions = filetypes.split() for x in Bowser.links(): link = re.search(pattern, str(x)).group()[6:-1] for y in extensions: if link.endswith(y): print('Downloading: ' + link) try: Bowser.download_link( link, os.path.join(directory, os.path.split(link)[1])) except Exception: print(sys.exc_info()) break if numb == 1: number.number(directory, filetypes)
def numberget(): number_data = mysql_number() x, y = load_number() inlier, outlier, test_data, l1, l2, l3, l4 = number(x, y) return jsonify({ 'numberdata': number_data, "inlier": inlier, 'outlier': outlier, 'test_data': test_data, 'l1': l1, 'l2': l2, 'l3': l3, 'l4': l4 })
def segmentation (img_gray_filtr, thresh, fg_tresh_max, fg_tresh_min, bg_tresh_max, bg_tresh_min): import cv2 as cv import numpy as np from number import number # PROGOWANIE ___________________________________________________________________________________________________________ img_bin = cv.adaptiveThreshold(img_gray_filtr, thresh, cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY_INV, fg_tresh_max, fg_tresh_min) img_bin_bg = cv.adaptiveThreshold(img_gray_filtr, thresh, cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY_INV, bg_tresh_max, bg_tresh_min) # MORFOLOGIA ___________________________________________________________________________________________________________ kernel = cv.getStructuringElement(cv.MORPH_ELLIPSE, (5, 5)) kernel_d = cv.getStructuringElement(cv.MORPH_RECT, (3, 3)) kernel_e = cv.getStructuringElement(cv.MORPH_CROSS, (3, 3)) maska_fg_true = cv.dilate(img_bin, kernel_d, iterations=4) sure_fg = cv.erode(maska_fg_true, kernel_e, iterations=3) sure_fg = np.uint8(sure_fg) maska_bg_true = cv.erode(img_bin_bg, kernel_d, iterations=1) sure_bg = cv.dilate(maska_bg_true, kernel, iterations=7) # WATHERSHED ___________________________________________________________________________________________________________ unknown = cv.subtract(sure_bg, sure_fg) _, markers = cv.connectedComponents(sure_fg) markers = markers+1 markers[unknown == 255] = 0 img_color = cv.cvtColor(img_gray_filtr, cv.COLOR_GRAY2BGR) edges = cv.watershed(img_color, markers) # WYBIERANIE NACZYNIA __________________________________________________________________________________________________ seed = np.copy(img_gray_filtr) seed[:, :] = [0] number_img = number(edges+1) seed[edges == 2] = 1 # ################################################ KONIEC SEGMENTACJI ################################################ # return seed
def test_should_handle_normal_cases(): assert number(["a", "b", "c"]) == ["1: a", "2: b", "3: c"]
def test_should_handle_empty_arrays(): assert number([]) == []
def test_should_handle_some_empty_lines(): assert number(["", "b", "", "", ""]) == ["1: ", "2: b", "3: ", "4: ", "5: "]
# Largest prime factor # Problem 3 # The prime factors of 13195 are 5, 7, 13 and 29. # What is the largest prime factor of the number 600851475143 ? from number import number import time t = time.time() num = 600851475143 # Trouver tous les facteurs du nombre # On teste seulement les nombres allant de 0 à la racine de num a = number(num) factor = a.findFactors() # Trouver les nombres premiers et trouver le plus grand primeList = [] for i in range(len(factor) - 1): a = number(factor[i]) if a.isPrime() is True: primeList.append(factor[i]) print(max(primeList)) print(time.time() - t) # 6 857
Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring cycle. Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part. analyze: 1/7: int(10/7)=1 int((10 - 7)*10/7)=4 ... ''' import sys import os sys.path.append(os.path.dirname(sys.argv[0]) + "\\..\\common\\") import number N = number.number() def get_result(): max = 0 lasti = 0 for i in range(1, 1001): n = N.recurring_number_divide_by_1(i) if n > max: max = n lasti = i return str(lasti) if __name__ == "__main__": print("result is : %s" % get_result())
import numpy as np from extract import extract from color import color from number import number import number_old COL = 0 # R=0, G=1, P=2 NUM = 1 # 1=1, 2=2, 3=3 SHADE = 2 # E=0, S=1, F=2 SHAPE = 3 # O=0, D=1, S=2 NCARDS = 9 # Number of cards in image - can be automated later res = np.empty([9, 4], dtype=np.uint8) card = extract('set.jpg', NCARDS) for i in range(NCARDS): res[i, COL] = color(card[i]) res[i, NUM] = number(card[i]) res[i, SHADE] = number_old.number(card[i]) print(res)
# Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b # and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b are called amicable numbers. # For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. # The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220. # # Evaluate the sum of all the amicable numbers under 10000. from number import number import time t = time.time() am_num = [] for i in range(10000): a = number(i) mult = [] if a.isPrime() is True: continue else: mult = a.findFactors() mult.remove(i) num2 = sum(mult) b = number(num2) if b.isPrime() is True: continue else: mult2 = b.findFactors() mult2.remove(num2) sum2 = sum(mult2) if sum2 == i and num2 != i:
def test_rand(self): for i in range(100): arr = [chr(randint(48, 122)) for i in range(100)] self.assertEqual( number(arr[:]), [str(key + 1) + ": " + val for (key, val) in enumerate(arr)])
def test_number(): assert number([[10, 0], [3, 5], [5, 8]]) == 5 assert number([[3, 0], [9, 1], [4, 10], [12, 2], [6, 1], [7, 10]]) == 17 assert number([[3, 0], [9, 1], [4, 8], [12, 2], [6, 1], [7, 8]]) == 21 assert number([[0, 0]]) == 0
# nb += 1 # mid = np.sqrt(nb) # mid = round(mid) # # if nb % 2 == 0 and nb != 2: # continue # # for x in range(1, int(mid) + 1, 1): # rest = nb % x # if rest == 0: # factor.append(x) # factor.append(nb / x) # # if len(factor) == 2: # summ += nb while nb < limite: nb += 1 a = number(nb) if nb > 5: if nb % 2 == 0 or nb % 3 == 0 or nb % 5 == 0: continue if a.isPrime() is True: summ += nb else: continue print(summ) print(time.time() - s) # 142 913 828 922
# 6: 1,2,3,6 # 10: 1,2,5,10 # 15: 1,3,5,15 # 21: 1,3,7,21 # 28: 1,2,4,7,14,28 # We can see that 28 is the first triangle number to have over five divisors. # # What is the value of the first triangle number to have over five hundred divisors? from number import number import time t = time.time() mult = [] num = 1 while len(mult) < 500: mult = [] num += 1 a = number(num) if a.isPrime() is True: continue else: mult = a.findFactors() print(num) print(time.time() - t) # 76 576 500 # takes too much time
A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number. A number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n. As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit. Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers. ''' import sys import os sys.path.append(os.path.dirname(sys.argv[0]) + "\\..\\common\\") import number N = number.number() UNKNOWN_NUMBER=0 PERFECT_NUMBER=1 DEFICIENT_NUMBER=2 ABUNDANT_NUMBER=3 g_number_type={} def number_type(num): global g_number_type if g_number_type.get(num) != None: return g_number_type[num]
where |n| is the modulus/absolute value of n e.g. |11|=11 and |−4|=4 Find the product of the coefficients, a and b, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n=0. ''' from number import number numList = [] lenList = [] coeffList = [] for a in range(999, -1000, -1): for b in range(1000, -1001, -1): v = number(b) if v.isPrime() == False: continue else: n = 0 prime = True while prime == True: num = n**2 + a * n + b n += 1 d = number(num) prime = d.isPrime() if prime == False: break elif prime == True: numList.append(num) lenList.append(len(set(numList)))