I've always hated that gay joke. Circular logic is not (good) recursion. >in order to solve n, you have to solve n-1 >so when do you stop? >exactly
not funny, but much more accurate
you sure can, it will just overflow the stack eventually and so is moronic. but that's not what >in order to understand recursion, you must understand recursion
implies. that statement implies >def solve(n): >solve(n)
as I said, that's not good recursion. the whole point is to solve n by solving a smaller problem (n-1).
4 weeks ago
Anonymous
What an autistic hill to die on
4 weeks ago
Anonymous
just doing my part to prevent the spread of moronation!
4 weeks ago
Anonymous
you sure can, it will just overflow the stack eventually and so is moronic. but that's not what >in order to understand recursion, you must understand recursion
implies. that statement implies >def solve(n): >solve(n)
as I said, that's not good recursion. the whole point is to solve n by solving a smaller problem (n-1).
you are such a wienersucking gay moron redditor it's insane
4 weeks ago
Anonymous
I've always hated that gay joke. Circular logic is not (good) recursion. >in order to solve n, you have to solve n-1 >so when do you stop? >exactly
not funny, but much more accurate
Your example is literally what's called a "tail" recursion, it's like a GOTO statement, so it doesn't increment the call stack.
From wikipedia on tail recursion: > Many implementations achieve this by using a device known as a trampoline, a piece of code that repeatedly calls functions. All functions are entered via the trampoline. When a function has to tail-call another, instead of calling it directly and then returning the result, it returns the address of the function to be called and the call parameters back to the trampoline (from which it was called itself), and the trampoline takes care of calling this function next with the specified parameters.
> Because tail calls are treated as jumps tail recursion can be used for indefinite iteration without fear of overflowing any sort of recursion stack.
I herefore use this opportunity to call you dimwit.
4 weeks ago
Anonymous
not all languages optimize tail recursion. my example being one of them. dimwit.
Obligitory, In order to understand recursion, you need to understand recursion.
imagine shoving your hand so far up your own ass that it eventually makes its way down your arm and your fingers end up being around themselves
Since we into that
Let's explain right way
You want to show your hand up your ass
You clone yourself and tell the clone to show his ass up your ass
Your clone also wants to show his hand up his ass
He creates another clone, clone of himself, clone of your clone
He tell the clone to show his hand up his ass
Now this clone clone also wants to show his hand up his ass
He creates another clone, clone of himself, clone of the clone of our clone
...
The process continues until universe is exhausted (stackoverflow/max call stack exceeded) or last clone is just a bit straight enough to not want showing his hand up his ass (exit/return condition reached).
(1) You are given a small problem,
you know how to solve this problem directly
so you do so and return the result.
(2) You are given a problem that you don't know how to solve directly,
but you know how to break it up into some smaller problems.
So you break it up into those pieces and ask someone else to solve those smaller pieces.
Then you take all the solutions you get back, combine them into a solution for the problem you were originally given and you return that.
this. >at the theater >oh shit what row am I in
1. ask the guy in front of you
2. if he doesn't know, tell him to follow these steps and get back to you
3. add 1 to what he tells you and report back
Recursion IS while loops. There's some implicit syntax sugar, but in the end it's just a loop with variable assignment.
It all boils down to breadth first or depth first searching.
>There's some implicit syntax sugar
This isn't true even in most languages.
a function calling itself can blow the stack unless the compiler or interpreter has tail call optimization
no such limitation exists for loops even in naive implementations
anything you would use a loop for, you can also solve using recursion.
recursion happens to be a convenient way to solve certain problems, especially ones with lots of branching paths.
Try to implement depth first search using loops. Then try to implement it using a function that calls itself.
It's easy to understand recursion if you're dealing with any sort of problem involving graphs or trees, then it becomes very immediately intuitive. So, look into those.
you ever had a really bad case of diarrhea from eating tacoslop that was on sale but because its onsale you just keep buying it to eart bacons ints on.sale?
>Iterator implementation: do X when the condition evaluates to true, usually time O(n) and space O(1) >Recursive implementation: figure out the condition it stops, set a base case to stop, then have to spend shit ton of brainpower to figure out if shit is correctly implemented in the tail recursion or else shit won't get called the right way on returning time, all this effort to implement it and never provides a constant space solution
Only homosexual brainlets use unnecessary recursion in their code base fricking up the stack frame in the name of "m-muh recursion makes code readability better it's heckin elegant!!" when iterators are in many cases better than recursive implementation of some shit. You're not missing out for not understanding recursion.
imagine shoving your hand so far up your own ass that it eventually makes its way down your arm and your fingers end up being around themselves
Obligitory, In order to understand recursion, you need to understand recursion.
I've always hated that gay joke. Circular logic is not (good) recursion.
>in order to solve n, you have to solve n-1
>so when do you stop?
>exactly
not funny, but much more accurate
You can have recursion that doesn't terminate.
you sure can, it will just overflow the stack eventually and so is moronic. but that's not what
>in order to understand recursion, you must understand recursion
implies. that statement implies
>def solve(n):
>solve(n)
as I said, that's not good recursion. the whole point is to solve n by solving a smaller problem (n-1).
What an autistic hill to die on
just doing my part to prevent the spread of moronation!
you are such a wienersucking gay moron redditor it's insane
Your example is literally what's called a "tail" recursion, it's like a GOTO statement, so it doesn't increment the call stack.
From wikipedia on tail recursion:
> Many implementations achieve this by using a device known as a trampoline, a piece of code that repeatedly calls functions. All functions are entered via the trampoline. When a function has to tail-call another, instead of calling it directly and then returning the result, it returns the address of the function to be called and the call parameters back to the trampoline (from which it was called itself), and the trampoline takes care of calling this function next with the specified parameters.
> Because tail calls are treated as jumps tail recursion can be used for indefinite iteration without fear of overflowing any sort of recursion stack.
I herefore use this opportunity to call you dimwit.
not all languages optimize tail recursion. my example being one of them. dimwit.
Since we into that
Let's explain right way
You want to show your hand up your ass
You clone yourself and tell the clone to show his ass up your ass
Your clone also wants to show his hand up his ass
He creates another clone, clone of himself, clone of your clone
He tell the clone to show his hand up his ass
Now this clone clone also wants to show his hand up his ass
He creates another clone, clone of himself, clone of the clone of our clone
...
The process continues until universe is exhausted (stackoverflow/max call stack exceeded) or last clone is just a bit straight enough to not want showing his hand up his ass (exit/return condition reached).
Really, what seems to be the problem?
Anon what's the meaning of GIMP
Gay is my peepee
(1) You are given a small problem,
you know how to solve this problem directly
so you do so and return the result.
(2) You are given a problem that you don't know how to solve directly,
but you know how to break it up into some smaller problems.
So you break it up into those pieces and ask someone else to solve those smaller pieces.
Then you take all the solutions you get back, combine them into a solution for the problem you were originally given and you return that.
this.
>at the theater
>oh shit what row am I in
1. ask the guy in front of you
2. if he doesn't know, tell him to follow these steps and get back to you
3. add 1 to what he tells you and report back
recursion is cope
use while loops instead
Recursion IS while loops. There's some implicit syntax sugar, but in the end it's just a loop with variable assignment.
It all boils down to breadth first or depth first searching.
>depth first
while loop + lifo stack
>breadth first
while loop + fifo queue
>There's some implicit syntax sugar
This isn't true even in most languages.
a function calling itself can blow the stack unless the compiler or interpreter has tail call optimization
no such limitation exists for loops even in naive implementations
>no such limitation exists for loops even in naive implementations
well... the limitation is moved from the callstack to some heap structure.
>he hasn't heard of the ackerman function
just search on google some exercises, recursion is a difficult concept to gasp at first, but with a couple hours of exercises you'll understand it
>filtered
It's easy.
>Recursion solves recursive problems by using functions that call themselves from within their own code.
Read chapter 8, it starts at page 243
https://www.cs.cmu.edu/~dst/LispBook/book.pdf
Thank you for sharing that link.
anything you would use a loop for, you can also solve using recursion.
recursion happens to be a convenient way to solve certain problems, especially ones with lots of branching paths.
Try to implement depth first search using loops. Then try to implement it using a function that calls itself.
learn mathematical induction
if that's too hard learn math
the return value for a recursive function is that same function with the original arguments but iterated in some manner. how is that hard to get?
function in a function
simple
vacuous statement
It would be more accurate to say:
function(function(XD))
I enjoy your vocabulary. It is also fun to say out loud.
>It is also fun to say out loud.
you know what else is fun to say out loud?
recursion uses the memory stack so learn and understand that first.
>
unironically the best way to learn recursion
It's easy to understand recursion if you're dealing with any sort of problem involving graphs or trees, then it becomes very immediately intuitive. So, look into those.
funny dog
you ever had a really bad case of diarrhea from eating tacoslop that was on sale but because its onsale you just keep buying it to eart bacons ints on.sale?
>Iterator implementation: do X when the condition evaluates to true, usually time O(n) and space O(1)
>Recursive implementation: figure out the condition it stops, set a base case to stop, then have to spend shit ton of brainpower to figure out if shit is correctly implemented in the tail recursion or else shit won't get called the right way on returning time, all this effort to implement it and never provides a constant space solution
Only homosexual brainlets use unnecessary recursion in their code base fricking up the stack frame in the name of "m-muh recursion makes code readability better it's heckin elegant!!" when iterators are in many cases better than recursive implementation of some shit. You're not missing out for not understanding recursion.
what's not to understand?
ok imagine I make a function that can read one or more pages of posts.
and it takes a parameter so you say how many pages you want to read.
pages is 3
it reads through a page, if pages > 0 then it calls the same function (this is the recursion bit) with pages-1 and adds to the result
so now it keeps going
pages is 2
it reads through a page, pages > 0 then it calls the same function (this is the recursion bit) with pages-1 and adds to the result
pages is 1
it reads through a page, pages > 0 then it calls the same function (this is the recursion bit) with pages-1 and adds to the result
pages is 0
it reads through a page, pages == 0 so it adds to the result and the whole thing returns
Haha what stupid looking dog haha
also you a moron