from functools import reduce
def es_pot7(n):
"""
n es un entero no negativo.
retorna True si y solo si n es potencia de 7
"""
if n == 0:
return False
elif n == 1:
return True
elif n%7 != 0:
return False
else:
return es_pot7(n//7)
def tiene_bloque_pot7(n, lst):
return reduce(lambda acum, x: [(acum[0]+1 if es_pot7(x) else 0), (acum[0]+1 if acum[0]>acum[1] else acum[1])], lst, [0, 0])[1]==n
print(tiene_bloque_pot7(4,[1, 0, 1, 49, 7, 7, 14])) # True
print(tiene_bloque_pot7(3,[1, 0, 1, 49, 7, 7, 14])) # False
print(tiene_bloque_pot7(4,[1, 49, 7, 7*7*7, 14])) # True
print(tiene_bloque_pot7(1,[3, 5, 11, 14, 21])) # False