-
Notifications
You must be signed in to change notification settings - Fork 20
Гоголев 1 2 3 4 5 6 10 11 #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
f9e3930
4d98a3a
463da05
7c373ac
31b8847
6106aa6
2d5d0f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import unittest | ||
| from Zadacha10 import PIF_COUTNER | ||
|
|
||
|
|
||
| class TestSorting(unittest.TestCase): | ||
| def test_1(self): | ||
| arr = [3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5] | ||
| res = PIF_COUTNER(arr) | ||
| expected = 1 | ||
| self.assertEqual(expected, res) | ||
|
|
||
| def test_2(self): | ||
| arr = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5] | ||
| res = PIF_COUTNER(arr) | ||
| expected = 0 | ||
| self.assertEqual(expected, res) | ||
|
|
||
| def test_3(self): | ||
| arr = [5] | ||
| res = PIF_COUTNER(arr) | ||
| expected = 0 | ||
| self.assertEqual(expected, res) | ||
|
|
||
| def test_4(self): | ||
| arr = [] | ||
| res = PIF_COUTNER(arr) | ||
| expected = 0 | ||
| self.assertEqual(expected, res) | ||
|
|
||
| def test_5(self): | ||
| arr = [3, 4, 5] | ||
| res = PIF_COUTNER(arr) | ||
| expected = 1 | ||
| self.assertEqual(expected, arr) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| from sys import stdin | ||
|
|
||
| FIRST_LINE = stdin.readline() | ||
| LIST = [int(p) for p in FIRST_LINE.split(' ')] | ||
|
|
||
|
|
||
| def PIF_COUTNER(LIST): | ||
| HELP_LIST = set(LIST) | ||
| LIST2 = list(HELP_LIST) | ||
| LIST2.sort() | ||
| COUNTER = 0 | ||
| for i in range(0, len(LIST2)): | ||
| for j in range(0, len(LIST2)): | ||
| for k in range(0, len(LIST2)): | ||
| if LIST2[i] ** 2 + LIST2[j] ** 2 == LIST2[k] ** 2: | ||
| COUNTER = COUNTER + 1 | ||
| return int(COUNTER / 2) | ||
|
|
||
|
|
||
| print(PIF_COUTNER(LIST)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import unittest | ||
| from Zadacha11 import SQUARE | ||
| from Zadacha11 import MAX_SQUARE | ||
|
|
||
|
|
||
| class TestSorting(unittest.TestCase): | ||
| def test_1(self): | ||
| arr = [2, 5, 1, 2, 3, 4, 7, 7, 6] | ||
| res = MAX_SQUARE(arr) | ||
| expected = 10 | ||
| self.assertFalse(not res) | ||
| self.assertEqual(expected, res) | ||
|
|
||
| def test_2(self): | ||
| arr = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5] | ||
| res = MAX_SQUARE(arr) | ||
| expected = 0 | ||
| self.assertFalse(not res) | ||
| self.assertEqual(expected, res) | ||
|
|
||
| def test_3(self): | ||
| arr = [5] | ||
| res = MAX_SQUARE(arr) | ||
| expected = 0 | ||
| self.assertFalse(not res) | ||
| self.assertEqual(expected, res) | ||
|
|
||
| def test_4(self): | ||
| arr = [] | ||
| res = MAX_SQUARE(arr) | ||
| expected = 0 | ||
| self.assertFalse(not res) | ||
| self.assertEqual(expected, res) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from sys import stdin | ||
|
|
||
| first_line = stdin.readline() | ||
| list = [int(p) for p in first_line.split(' ')] | ||
|
|
||
|
|
||
| def SQUARE(i): | ||
| square = 0 | ||
| j = i + 1 | ||
| p = i + 2 | ||
| while j < len(list) and list[i] > list[j]: | ||
| square = square + (list[i] - list[j]) | ||
| j = j + 1 | ||
| p = p + 1 | ||
| if j != len(list): | ||
| return square | ||
| else: | ||
| return 0 | ||
|
|
||
|
|
||
| def MAX_SQUARE(list): | ||
| s = 0 | ||
| for x in range(0, len(list) - 1): | ||
| if SQUARE(x) > s: | ||
| s = SQUARE(x) | ||
| return s | ||
|
|
||
|
|
||
| print(MAX_SQUARE(list)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import math | ||
|
|
||
| n = raw_input('name: ') | ||
|
|
||
| m = math.sqrt(float(n)) | ||
|
|
||
| c = True | ||
|
|
||
| a = [False] | ||
|
|
||
| for i in xrange(2, int(n)): | ||
| for x in xrange(2,int(m)): | ||
| if i % x == 0 and i != x : | ||
| c = False | ||
| a = a + [c] | ||
| c = True | ||
| print a | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| from sys import stdin | ||
|
|
||
| first_line = stdin.readline() | ||
| second_line = stdin.readline() | ||
| c = 0 | ||
| n = int(first_line) | ||
| l = [int(p) for p in second_line.split(' ')] | ||
|
|
||
|
|
||
| def function(index, m): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. название должно о чём-нибудь говорить |
||
| global c | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. глобальные изменяемые переменные очень сложно отлаживать, лучше, когда функция не зависит от внешнего состояния, учтите на будущее |
||
| for i in range(0, int((m / l[index]) + 1)): | ||
| k = m - i * l[index] | ||
| if k == 0: | ||
| c = c + 1 | ||
| else: | ||
| if index < (l.__len__() - 1): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. len(l). и не называйте переменную l, очень неудобно |
||
| function(index + 1, k) | ||
|
|
||
|
|
||
| function(0, n) | ||
| print(c) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| from sys import stdin | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. код работал больше минуты и не завершился, похоже у вас где-то вечный цикл, поправьте, пожалуйста
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Можно ли узнать, какие числа вы ввели, что у вас сломалась программа, пожалуйста?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. я передаю 1000000 случайных чисел от -10000 до 10000, а потом отдельно столько же нулей |
||
|
|
||
| first_line = stdin.readline() | ||
| list = [int(p) for p in first_line.split(' ')] | ||
| k = 10 | ||
|
|
||
|
|
||
| def INSERTION_SORT(list): | ||
| for j in range(1, len(list)): | ||
| key = list[j] | ||
| i = j - 1 | ||
| while (i >= 0) and (list[i] > key): | ||
| list[i+1] = list[i] | ||
| i = i - 1 | ||
| list[i+1] = key | ||
| return list | ||
|
|
||
|
|
||
| def MERGE(leftpart, rightpart): | ||
| list = [] | ||
| while leftpart and rightpart: | ||
| if leftpart[0] < rightpart[0]: | ||
| list.append(leftpart.pop(0)) | ||
| else: | ||
| list.append(rightpart.pop(0)) | ||
| if leftpart: | ||
| list.extend(leftpart) | ||
| if rightpart: | ||
| list.extend(rightpart) | ||
| return list | ||
|
|
||
|
|
||
| def MERGE_SORT(list): | ||
| length = len(list) | ||
| if length >= 10: | ||
| mid = int(length / 2) | ||
| list = MERGE(MERGE_SORT(list[:mid]), MERGE_SORT(list[mid:])) | ||
| else: | ||
| list = INSERTION_SORT(list) | ||
| return list | ||
|
|
||
|
|
||
| print(MERGE_SORT(list)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| from sys import stdin | ||
| import random | ||
|
|
||
| c = 0 | ||
| d = 0 | ||
| e = 0 | ||
|
|
||
| first_line = stdin.readline() | ||
| list = [int(p) for p in first_line.split(' ')] | ||
|
|
||
|
|
||
| def QSORT(list, p, r): | ||
| if p < r: | ||
| q = RANDOM_PATRITION(list, p, r) | ||
| QSORT(list, p, q - 1) | ||
| QSORT(list, q + 1, r) | ||
| return list | ||
|
|
||
|
|
||
| def PATRITION(list, p, r): | ||
| x = list[r] | ||
| i = p - 1 | ||
| for j in range(p, r): | ||
| if list[j] < x: | ||
| i += 1 | ||
| d = list[i] | ||
| list[i] = list[j] | ||
| list[j] = d | ||
| e = list[i + 1] | ||
| list[i + 1] = list[r] | ||
| list[r] = e | ||
| return i + 1 | ||
|
|
||
|
|
||
| def RANDOM_PATRITION(list, p, r): | ||
| i = random.randint(p, r) | ||
| c = list[r] | ||
| list[r] = list[i] | ||
| list[i] = c | ||
| return PATRITION(list, p, r) | ||
|
|
||
|
|
||
| QSORT(list, 0, len(list) - 1) | ||
| print(list) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import unittest | ||
| from Zadacha6 import RADIX_SORT | ||
|
|
||
|
|
||
| class TestSorting(unittest.TestCase): | ||
| def test_trivial(self): | ||
| arr1 = [1, 333, 22] | ||
| arr2 = [] | ||
| res = RADIX_SORT(arr1, arr2) | ||
| expected = [1, 22, 333] | ||
| self.assertFalse(not res) | ||
| self.assertEqual(expected, res) | ||
|
|
||
| def test_empty(self): | ||
| arr1 = [] | ||
| arr2 = [] | ||
| res = RADIX_SORT(arr1, arr2) | ||
| expected = [] | ||
| self.assertEqual(expected, res) | ||
|
|
||
| def test_1(self): | ||
| arr1 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | ||
| 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 8] | ||
| arr2 = [] | ||
| res = RADIX_SORT(arr1, arr2) | ||
| expected = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | ||
| 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 8] | ||
| self.assertEqual(expected, res) | ||
|
|
||
| def test_2(self): | ||
| arr1 = [] | ||
| arr2 = [-111, -222, -333, -123, -321, -231, -213, -132, -312, -10, -5] | ||
| res = RADIX_SORT(arr1, arr2) | ||
| expected = [-333, -321, -312, -231, -222, -213, -132, -123, -111, -10, -5] | ||
| self.assertEqual(res, expected) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| from sys import stdin | ||
| import math | ||
|
|
||
| FIRST_LINE = stdin.readline() | ||
| LIST = [int(p) for p in FIRST_LINE.split(' ')] | ||
| LIST1 = [] | ||
| LIST2 = [] | ||
|
|
||
| for x in LIST: | ||
| if x >= 0: | ||
| LIST2.append(x) | ||
| else: | ||
| LIST1.append(x) | ||
|
|
||
| d = len(str(max(LIST))) | ||
|
|
||
|
|
||
| def RADIX_SORT_1(LIST, d): | ||
| for i in range(0, d): | ||
| HELP_LIST = [[] for k in range(0, 10)] | ||
| for x in LIST: | ||
| RADIX_VALUE = (x // (10 ** i)) % 10 | ||
| HELP_LIST[RADIX_VALUE].append(x) | ||
| LIST = [] | ||
| for k in range(0, 10): | ||
| LIST = LIST + HELP_LIST[k] | ||
| return LIST | ||
|
|
||
|
|
||
| def RADIX_SORT(LIST1, LIST2): | ||
| LIST3 = [] | ||
| for x in LIST1: | ||
| x = x * (-1) | ||
| LIST3.append(x) | ||
| LIST3 = RADIX_SORT_1(LIST3, d) | ||
| LIST4 = [] | ||
| for x in LIST3: | ||
| x = x * (-1) | ||
| LIST4.append(x) | ||
| LIST4.reverse() | ||
| LIST2 = RADIX_SORT_1(LIST2, d) | ||
| LIST3 = LIST4 + LIST2 | ||
| return LIST3 | ||
|
|
||
|
|
||
| print(RADIX_SORT(LIST1, LIST2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
у вас 1 простое число, поправьте, пожалуйста