retrait dossier sources recursivité

This commit is contained in:
Florian Mathieu
2024-09-17 21:37:38 +02:00
parent 1ddc046f95
commit 3cb7064576
8 changed files with 0 additions and 2500 deletions

View File

@@ -1,31 +0,0 @@
from functools import lru_cache
from functools import cache
@cache
def steps_to(stair):
if stair == 1:
# You can reach the first stair with only a single step from the floor.
return 1
elif stair == 2:
# You can reach the second stair by jumping from the floor with a single two-stair hop or by jumping a single stair a couple of times.
return 2
elif stair == 3:
# You can reach the third stair using four possible combinations:
# 1. Jumping all the way from the floor
# 2. Jumping two stairs, then one
# 3. Jumping one stair, then two
# 4. Jumping one stair three times
return 4
else:
# You can reach your current stair from three different places:
# 1. From three stairs down
# 2. From two stairs down
# 2. From one stair down
# If you add up the number of ways of getting to those
# those three positions, then you should have your solution.
return steps_to(stair - 3) + steps_to(stair - 2) + steps_to(stair - 1)
print(steps_to(35))