Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
for recursion, it's important to define the terminating condition
if (p0>= p) return 0
.Note that
0
is an identity value for addition (1 + 0 =1
).It's also important to consider using
tail recursion
to avoidStackOverflowError
i.e.
1 + nbYear
instead ofnbYear + 1
that way compiler can optimize calls
e.g (1 + (1 + nbYear)) -> 2 + nbYear
instead of (nbYear + (nbYear + 1))