DEV Community

Discussion on: Daily Challenge #88 - Recursive Ninjas

Collapse
 
pbouillon profile image
Pierre Bouillon • Edited

Small solution in Python 3.X 😄

def recursive_ninjas(nb: int) -> str:
  return 'chirp.' if nb == 1 else f'chirp-{recursive_ninjas(nb - 1)}'
Collapse
 
aminnairi profile image
Amin

Nice one! But you forgot an edge case. I can still call it with a negative value and get a recursion error.

print(recursive_ninjas(-10));
# RecursionError: maximum recursion depth exceeded in comparison

I think you should add another if else branch for when the value is less or equal than zero.

Collapse
 
pbouillon profile image
Pierre Bouillon • Edited

Given some context, which is ninjas talking, I doubt that they can talk negativly or that not talking at all is considered as talking

However, without those information, I fully agree ! 😄

Thread Thread
 
aminnairi profile image
Amin

I was reading the old ninja scroll all wrong... Thanks sensei 😁