Closed simonvonhackewitz closed 1 week ago
I've added a tail recursive version as a second example. I've only included a running example for it and left out the code version, take a look at the html file and let me know if a different way is preferred.
Also both version don't work for negative numbers. Does that matter for an idiom?
And if so, whats the best way to handle it? Change the argument type to u32
, then it will have a different type than the default type of constants or loop variables, or add a precondition?
Either change the type to u32
and deal with the consequences, or use a precondition.
Not sure if there is a better way to do this. The idiom description says that naive recursion is extremely inefficient for this task, but the other language do it similarly.