Last active
July 21, 2019 16:20
-
-
Save igorzakhar/b5b8ed7936bc07ff41e306c4a2168f47 to your computer and use it in GitHub Desktop.
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
from yandex_task import output_result | |
import pytest | |
class TestOutputResult: | |
def test_one_element(self): | |
assert(output_result(1, (10,)) == '32') | |
def test_tree_element(self): | |
assert(output_result(3, (4, 5, 4)) == '3 5 3') | |
def test_four_element(self): | |
assert(output_result(4, (0, 1, 2, 3)) == '0 1 2 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
from functools import lru_cache | |
@lru_cache(maxsize=1000) | |
def find_elem(elem): | |
if elem in (0, 1, 2): | |
return elem | |
else: | |
return find_elem(elem - 1) + find_elem(elem - 3) | |
def read_stdin(): | |
try: | |
while True: | |
data = input() | |
if not data: | |
break | |
yield data | |
except EOFError: | |
return | |
if __name__ == '__main__': | |
input_data = list(read_stdin()) | |
n = int(input_data[0]) | |
sequence = list(map(int, input_data[1].split())) | |
elements = [find_elem(sequence[i]) for i in range(n)] | |
print(', '.join(map(str, elements))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment