Вот решение 173-й задачи (оно есть на сайте):
def f( start, end, lastCmd = 0 ):
if start == end: return 1
if start == 33 or start > end: return 0
count = f( start+1, end, 1 )
count += f( start+3, end, 2 ) if start not in [16,17] else 0
count += f( start*2, end, 3 ) if lastCmd != 3 and not(10<=start<=17) else 0
return count
print( f( 2, 51 ) )
Третий параметр - номер последней выполненной команды. Если он равен 3, то следующей командой не может быть команда 3.
Если текущая позиция 16 или 17, то команда 2 (+3) перепрыгивает 18, и поэтому такой вариант блокируется.
Команда 3 перепрыгивает 18 из позиций 10...17, поэтому эти варианты тоже блокируются.
Для ускорения можно добавить кэширование:
from functools import lru_cache
@lru_cache
def f( start, end, lastCmd = 0):
if start == end: return 1
if start == 33 or start > end: return 0
count = f( start+1, end, 1 )
count += f( start+3, end, 2 ) if start not in [16,17] else 0
count += f( start*2, end, 3 ) if lastCmd != 3 and not(10<=start<=17) else 0
return count
print( f( 2, 51 ) )