diff --git a/results/top_tracks.txt b/results/top_tracks.txt index 0278bc5..007cc52 100644 --- a/results/top_tracks.txt +++ b/results/top_tracks.txt @@ -36,6 +36,65 @@ if __name__ == "__main__": main() ============================= +# №7. Дешифровка Цезаря +def decode_caesar(text: str, shift: int) -> str: + res = "" + for c in text: + new = ord(c) - shift + if new < 1072: + new = new + 32 + res = res + chr(new) + return res + +# №8. НОД (алгоритм Евклида) +def gcd(a: int, b: int) -> int: + while b != 0: + temp = b + b = a % b + a = temp + return a + +# №3. Проверка пароля +def is_strong_password(password: str) -> bool: + if len(password) < 8: + return False + + has_digit = False + has_upper = False + + for c in password: + if c >= "0" and c <= "9": + has_digit = True + if c >= "A" and c <= "Z": + has_upper = True + + return has_digit and has_upper + +# №16. Удаление выбросов +def remove_outliers(numbers: list, threshold: float) -> list: + if len(numbers) == 0: + return [] + + # Считаем среднее + summa = 0 + for x in numbers: + summa = summa + x + mean = summa / len(numbers) + + # Считаем стандартное отклонение + sum_sq = 0 + for x in numbers: + sum_sq = sum_sq + (x - mean) ** 2 + std = (sum_sq / len(numbers)) ** 0.5 + + # Собираем результат + res = [] + for x in numbers: + if (x - mean) <= threshold * std and (mean - x) <= threshold * std: + res.append(x) + return res + + # 1. is_armstrong(n: int) -> bool # Проверяет, является ли число числом Армстронга. # Идея: переводим число в строку, считаем количество цифр,