Skip to content

Instantly share code, notes, and snippets.

@maintainer64
Created January 12, 2019 15:36
Show Gist options
  • Save maintainer64/1572d8b6e07336dd8b1b275abf19478d to your computer and use it in GitHub Desktop.
Save maintainer64/1572d8b6e07336dd8b1b275abf19478d to your computer and use it in GitHub Desktop.
def sequence_string(e, arr):
"""
This function solve task from https://vk.com/@unilecs-anons-44-posledovatelnost by the string method
:param e: string, len which = 1
:param arr: list of string, len which = 1
:return: bool
"""
# Кол-во символов e
n: int = 5
# e * n -> Строка символов `e` из `n` элементов
# ''.join(arr) -> Строка, в которой ищем вхождение e * n
return e * n in ''.join(arr)
def sequence(e, arr):
"""
This function solve task from https://vk.com/@unilecs-anons-44-posledovatelnost by the brute force method
:param e: string, len which = 1
:param arr: list of string, len which = 1
:return: bool
"""
# Кол-во символов e
n: int = 5
# Счётчик e подряд
ans: int = 0
# Переберём по символу в arr
# Условие прибавления счётчика -> Когда символ текущий из `arr` - совпадает с `e`
# Условие обнуление счётчика -> Когда символ текущий из `arr` - НЕ совпадает с `e`
# В самом конце проверка, если Счётчик набрал необходимое кол-во символов - выходим из ф-ии со знач. True
for _char in arr:
if _char == e:
ans += 1
else:
ans = 0
if ans == n:
return True
return False
if __name__ == '__main__':
assert sequence(e='s', arr=['s', 's', 's', 's', 's', 'f', 'd']), "First test"
assert not sequence(e='%', arr=['%', '%', '%', '%', 'd', '%']), "Second test"
print('Pretests passed')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment