Slow down; can you say that again? A function within the same function within the same function? If you were to tell me at the beginning of the semester that you could have a function that calls itself then I wouldn't have believed you. In fact, I sometimes still can't grasp the concept that there are functions that call itself repeatedly. How is it that you can write a function whose steps are dependent on itself? It was hard for me to wrap my head around this concept for quite a while.
It is handy, however, to have friends who are in the computer science field. One friend of mine called Matt brought me into the light that is recursions (he also gave me other helpful tips, such as my personal favorite "try googling it"). He told me to think of how factorials such as "5!" work. You are presented, literally, with a number and an exclamation mark. (At this point, I saw little of how this rationalization of factorials would help me understand recursion any better.) Then he told me to look at the number separate from the exclamation mark. If the number is not 1, then you multiply the number with the factorial of that number minus one. That would look something like this: (5 * 4!).
Woah, hold on a second. There it is! A factorial is inside the same factorial function! Lo and behold, I witnessed the genius of recursions right before my eyes. I finally figured out that recursions are not indeed endless loops that break the paradigms of the universe but actually a two-step process. If a value does not meet its requirements then you implement a change to the value and check for its requirements again. If it does meet the requirements then you return whatever value you need to. It's so simple yet why was it so difficult for me to figure out?
Through the help of my friends (and my ability to grasp my friends' knowledge) I was able to understand the seemingly impossible. No longer did recursions seem to me like a paradox, similar to the idea that someone can travel back in time to meet their former selves. Now that I realize that there are no loopholes in the theory of recursion, I feel like I can do the impossible. Maybe I should consider figuring out time travel now.
No comments:
Post a Comment