Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added lab1/Gogolev/Hello World.txt
Empty file.
34 changes: 34 additions & 0 deletions lab10/Gogolev/Tests10.py
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)
20 changes: 20 additions & 0 deletions lab10/Gogolev/Zadacha10.py
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))
33 changes: 33 additions & 0 deletions lab11/Gogolev/Zadacha11/Tests11.py
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)
29 changes: 29 additions & 0 deletions lab11/Gogolev/Zadacha11/Zadacha11.py
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))
18 changes: 18 additions & 0 deletions lab2/Gogolev/Zadacha2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import math

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

у вас 1 простое число, поправьте, пожалуйста


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

22 changes: 22 additions & 0 deletions lab3/Gogolev/Zadacha3.py
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):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

название должно о чём-нибудь говорить

global c

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(l). и не называйте переменную l, очень неудобно

function(index + 1, k)


function(0, n)
print(c)
43 changes: 43 additions & 0 deletions lab4/Gogolev/Zadacha4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from sys import stdin

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

код работал больше минуты и не завершился, похоже у вас где-то вечный цикл, поправьте, пожалуйста

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно ли узнать, какие числа вы ввели, что у вас сломалась программа, пожалуйста?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

я передаю 1000000 случайных чисел от -10000 до 10000, а потом отдельно столько же нулей
https://github.com/MikhailErofeev/a3200-2015-algs/blob/master/lab4/erofeev/randoms.py
https://github.com/MikhailErofeev/a3200-2015-algs/blob/master/lab6/erofeev/sortings_tests.sh
уходит в цикл на случайных


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))
44 changes: 44 additions & 0 deletions lab5/Gogolev/Zadacha5.py
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)
35 changes: 35 additions & 0 deletions lab6/Gogolev/Tests6.py
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)
46 changes: 46 additions & 0 deletions lab6/Gogolev/Zadacha6.py
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))