Skip to content

Commit

Permalink
Updated instructions
Browse files Browse the repository at this point in the history
-Updated Instructions.append.md
-Added hints.md
  • Loading branch information
PaulT89 committed Jul 30, 2022
1 parent a49fcba commit 62d6e65
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
10 changes: 10 additions & 0 deletions exercises/practice/pascals-triangle/.docs/hints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Hints

## General

- A more detailed description of recursive programming can be found [here][g4g]
- This exercise involves a test to ensure that you used a recursive solution
- If you are having trouble completing this exercise, try [using a loop first, and then convert it into a recursive solution][educative]

[g4g]: https://www.geeksforgeeks.org/recursion/
[educative]: https://www.educative.io/collection/page/6151088528949248/4547996664463360/6292303276670976
17 changes: 16 additions & 1 deletion exercises/practice/pascals-triangle/.docs/instructions.append.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
## Recursion

This exercise is designed to be completed using recursion, rather than loops.
MORE DESCRIPTION ABOUT RECURSIVE PROGRAMMING GOES HERE.
A recursive function is a function that calls itself, which is useful when solving problems that are defined in terms of themselves.
To avoid infinite recursion (or more specifically, to avoid overflowing the stack), something called a "base case" is used.
When the base case is reached, a non-recursive value is returned, which allows the previous function call to resolve and return its value, and so on, rippling back down the stack until the first function call returns the answer.
We could write a recursive function to find the answer to 5! (i.e. 5 * 4 * 3 * 2 * 1) like so:

````python
def factorial(number):
if number <= 1: # base case
return 1

return number * factorial(number - 1) # recursive case

print(factorial(5)) # returns 120
````

Finally, it should be noted that Python limits the number of times recursive calls can be made (1000 by default) and does not optimize for [tail recursion](https://www.geeksforgeeks.org/tail-recursion/).

## Exception messages

Expand Down

0 comments on commit 62d6e65

Please sign in to comment.