Skip to content
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

Rinat Salimov 05-703 Sort.md #6

Open
wants to merge 14 commits into
base: test
Choose a base branch
from
Open

Rinat Salimov 05-703 Sort.md #6

wants to merge 14 commits into from

Conversation

RinatSalimov
Copy link

/*"1 Сортировка вставками"
def insert_sort(A):
N=len(A)
for pop in range(N):
k = pop-1
while k>-1 and A[k]>A[k+1]:
A[k],A[k+1] = A[k+1],A[k]
k-=1

"2. Сортировка пузырьком"
def bubble_sort(A):
changed = True
while changed:
changed = False
for i in range(len(A) - 1):
if A[i] > A[i+1]:
A[i], A[i+1] = A[i+1], A[i]
changed = True

def test_sort(sort_algorithm):
print('test #1')
A=[5,4,3,2,1]
A_sorted=[1,2,3,4,5]
sort_algorithm(A)
if A==A_sorted:
print("OK")
else:
print("Fail")

A=[3,4,3,4,3]
A_sorted=[3,4,3,4,3]
sort_algorithm(A)
print("OK" if A==A_sorted else "Fail")

print('test #3')
A=[1,4,5,3,6,8,3,4,7]
A_sorted=[1,3,3,4,5,5,5,7,8]
sort_algorithm(A)
print("OK" if A==A_sorted else "Fail")

"3. Числа Фибоначчи. 1)Через циклы"

fib1 = fib2 = 1
n = int(input())
if n < 2 :
quit()

print(fib1, end = ' ')
print(fib2, end = ' ')
for i in range(2, n):
fib1, fib2 = fib2, fib1 + fib2
print(fib2, end = ' ')

print()

"2) Через рекурсию"
def fib(n):
if n == 1 or n == 2:
return 1
else:
return fib(n - 1) + fib(n - 2)

print(fib(int(input())))

"4. Нахождение НОДа"

def g(a,b):
if b! = 0:
if a > b :
return g(a, a%b)
elif a < b :
return g(a, b%a)
a = int(input())
b = int(input())
print(g(a,b))

"5. Быстрое возведение в степень"

def g(b,n):
if n == 0:
return 1
return n b*g(b,n-1)
b = int(input())
n = int(input())
print(g(b,n))

@RinatSalimov RinatSalimov changed the title Update README.md Rinat Salimov 05-703 Sort.md Mar 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants