Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
/*"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))