Created
September 8, 2020 07:07
-
-
Save asdfMaciej/bc11425ad62f2a00c4be8b965b5d5ecf to your computer and use it in GitHub Desktop.
MIN-R1_1P-202 - zad 1.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def czy_k_podobne(n, A, B, k): | |
if cmp(A, B, n) and k==0: | |
return True | |
# indeksy sa zmniejszone o 1 w porownaniu do zadania | |
# ze wzgledu na 0-indexing (w zad. jest 1-indexing) | |
if (cmp(slice(A, 0, k-1), slice(B, n-k, n-1), k) | |
and cmp(slice(A, k, n-1), slice(B, 0, n-k-1), n-k)): | |
return True | |
return False | |
def slice(t, a, b): | |
tab = [] | |
for i in range(b-a+1): | |
tab.append(t[i+a]) | |
return tab | |
def cmp(a, b, n): | |
for i in range(n): | |
if a[i] != b[i]: | |
return False | |
return True | |
print(czy_k_podobne(3, [5,7,9], [5,7,9], 0)) | |
print(czy_k_podobne(5, [4,7,1,4,5], [1,4,5,4,7], 2)) | |
print(czy_k_podobne(5, [10,9,12,10,9], [10,10,9,9,12], 3)) | |
print(czy_k_podobne(5, [3,6,5,1,8], [5,1,8,3,6], 4)) | |
print(czy_k_podobne(5, [1,2,3,4,5], [3,4,5,1,2], 2)) | |
print(czy_k_podobne(9, [1,1,1,1,3,1,1,1,1], [3,1,1,1,1,1,1,1,1], 4)) | |
print(czy_k_podobne(6, [4, 2, 4, 4, 2, 6], [4,4,2,6,4,2], 1)) | |
""" | |
Prostsze, ale zawiera operacje niedozwolone w zadaniu: | |
- array slices (tablica[start:end]) zamienione przez funkcje slice | |
- porownywanie calych tablic, zamienione przez funkcje cmp | |
def czy_k_podobne(n, A, B, k): | |
# zwraca k | |
if A == B and k==0: | |
return True | |
if A[0:k-1] == B[n-k:n-1] and A[k:n-1] == B[0:n-k-1]: | |
return True | |
return False | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment