-
Notifications
You must be signed in to change notification settings - Fork 22
Стариков Егор, 142 гр #7
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: main
Are you sure you want to change the base?
Changes from all commits
6468241
036d224
52916ac
83d498e
ede3402
51b4d7a
b0ef15f
c2dab4c
031ca20
6ba9207
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 |
|---|---|---|
| @@ -1,14 +1,38 @@ | ||
| def modulo11Checksum(ISBNNumber: str): | ||
| def modulo11checksum(isbn_number: str): | ||
|
|
||
| digits = [int(char) for char in ISBNNumber if char.isdigit()] | ||
| digits = [int(char) for char in isbn_number if char.isdigit()] | ||
|
|
||
| checkDigit = digits[-1] | ||
| if len(digits) < 9: | ||
|
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. Для ISBN-10 (с учетом X) должно быть ровно 9 или 10 цифр. Сейчас мы можем ввести |
||
| return False | ||
|
|
||
| last_char = isbn_number[-1] | ||
| if last_char.upper() == 'X': | ||
| check_digit = 10 | ||
| elif last_char.isdigit(): | ||
| check_digit = digits[-1] | ||
| else: | ||
| return False | ||
|
|
||
| total = 0 | ||
| for i in range(len(digits) - 1): | ||
| weight = 10 | ||
| for i in range(9): | ||
| weight = 10 - i | ||
| digit = digits[i] | ||
| total += digit * weight | ||
|
|
||
| checksum = total + checkDigit | ||
| checksum = total + check_digit | ||
| return checksum % 11 == 0 | ||
|
|
||
| print("Введите номер:") | ||
| s = input() | ||
| while True: | ||
| if modulo11checksum(s): | ||
| print("Все верно") | ||
| elif s == "-1": | ||
| break | ||
| else: | ||
| print("Что-то не так") | ||
| print("Введите номер:") | ||
| s = input() | ||
|
Comment on lines
+25
to
+35
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. Когда |
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,16 @@ | ||
| from src.bin_search import binSearch | ||
| from src.bin_search import bin_search | ||
|
|
||
|
|
||
| def test_middle(): | ||
| assert binSearch([1, 2, 3, 4, 5], 4) == 3 | ||
| assert bin_search([1, 2, 3, 4, 5], 3) == 2 | ||
|
|
||
| def not_sorted_list(): | ||
|
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.
|
||
| assert bin_search([2, 4, 1, 3], 1) == -1 | ||
|
|
||
|
|
||
| def test_start(): | ||
| assert binSearch([1, 2, 3, 4], 2) == 1 | ||
| assert bin_search([1, 2, 3, 4], 2) == 1 | ||
|
|
||
|
|
||
| def test_not_in_list(): | ||
| assert binSearch([1, 2, 3, 4], 5) == -1 | ||
| assert bin_search([1, 2, 3, 4], 5) == -1 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,20 @@ | ||
| from src.checksum import modulo11Checksum | ||
| from src.checksum import modulo11checksum | ||
|
|
||
|
|
||
| def test_good(): | ||
| assert modulo11Checksum("2-266-11156-8") | ||
| assert modulo11checksum("2-266-11156-6") | ||
|
|
||
|
|
||
| def test_bad(): | ||
| assert not modulo11Checksum("2-266-11156-3") | ||
| assert not modulo11checksum("2-266-11156-3") | ||
|
|
||
| def test_x(): | ||
| assert modulo11checksum("0-8044-2957-X") | ||
|
|
||
| def test_no_correct(): | ||
| assert not modulo11checksum("123456789Y") | ||
|
|
||
| def test_len(): | ||
| assert not modulo11checksum("31231") | ||
|
|
||
|
|
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.
Бинарный поиск должен работать за$O(\log{N})$ , добавляя цикл с проверкой на сортировку он начинает работать за $O(N)$ .