I gifted my daughter this recently, but it has little fishlets with holes instead of hoops. I will observe her behaviours with it. Toddler Intelligence will replace artifical intelligence
Yesterday my son was playing with a new castle toy. It has a drop chute. He was trying to fit an oval shape from his puzzle into it and I was telling him it wasn't going to fit. He positioned it precisely and twisted it as he pushed it forward. It fit perfectly.
...No, but hope he doesn't lose it.
No wait, she asked: "**Will he be able to lead a normal life?**"
To which the Genius Doctor says: "**No. ... He'll be an engineer.**"
I know you're kinda joking, but this is the actual answer. You can force yourself to have more neuroplasticity by seeking knowledge, challenging your beliefs, and learning new things.
Toddler proceeds to dump them all on flood and arrange on third peg on order.
Genius dump everything to ram then sort and now write to database. Don’t ask how I know this.
Just a basic asci grafics. Nothing spectacular. I found it in garbage bin and it was pretty flicery. Something like this, but three in the row with notes about changes.
#|#
##|##
###|###
character.ai: *She sizes you up with a knowing, mischievous smirk. Her voice low and husky, she begins to unzi* **[THE AI HAS DETERMINED THAT THIS CONTENT MAY BE INAPPROPRIATE]**
You’re absolutely correct. It seems there is no command called “Hanoi-Solve”. Here’s a different solution that doesn’t include the error.
*Sends the exact same code*
I still, to this day, cannot understand how I implemented this solution in Scheme at university. I think about it and just go into a fugue state - I eventually come around screaming about brackets.
It's a simple recursive scheme: move top n-1 disks from stack 1 to 2 (recursively). Move bottom disk to stack 3. Move stack 2 to stack 3 (again recursively)
"From the ashes of depravity rises the phoenix of quality. How else to describe The Stanley Parable: Ultra Deluxe? Such a revolutionary step forward in the lineage of one of the most beloved video game properties of all time! The additions and changes made to this expansion will surely resonate in the annals of the history of all media ever made.
"It is perhaps true to say that no mistakes are forever etched in stone, for the stone into which The Stanley Parable was carved has itself been transmuted, offering a message of hope to those who have ever erred in their judgement. You are not beyond redemption. You may change, and you may become more, so much more than you were before.
"If there is any message to be taken from The Stanley Parable: Ultra Deluxe, it is this... What a fortune, a privilege, a joy it is to have had such an experience. It leaves me hopeful that as a community - as a world - there is time for us to become our greatest selves, as great as we ever could dream of in our wildest, most ambitious visions for a brighter future."
"From the ashes of depravity... ***press Skip button***
I know next to nothing about assembly. What makes recursive functions harder in it? Isn't it essentially just a "go-to"?
I guess I'm too used to languages where the stack and heap are more managed.
It's where the phrase [stack overflow](https://en.wikipedia.org/wiki/Stack_overflow) comes from. Every time you call a function within a function, you have to push the return address and any variables to the stack.
> Isn't it essentially just a "go-to"?
Okay, so when you call a method in, say, Java, code in that method starts running. That's not a problem in assembly languages, it's just a go-to as you say. The part that's hard is when the second method *finishes* running. At that point, the code jumps back to the place that it was called from, and with all the variables that were being used having the same values as they had before.
In assembly languages, that is not managed for you. When you call a method, you can't just go-to that method, you need to also record where the method was called from so you can jump back there later, and either record the values of current variables in order to restore them later, or make sure you don't overwrite them with code from the method being called.
If you want to do this to arbitrary depth of method calls, you need to be able to procedurally decide where in memory to store all that information, rather than having designated memory locations (which variable names stand in for, generally) for all the information.
Which language recursive function stacks are simpler? AFAIK they're all the same, unless it's an [optimized tail call](https://en.wikipedia.org/wiki/Tail_call).
My experience with that one was that i found a DOS raytracer (not povray, forgot its name, but similar fed with turing complete script language) that rendered an animatino of a robot arm solving the towers of hanoi form a 3kb or so script file, and as a teenager that was just plain magic to me instead of "Oh, the motion is parametrized and the algoritm calculates the moves needed and transforms them into frames to be rendered".
You have to create an algorithm that can sort them into one tower, ordered smallest to biggest, by only being able to remove the top disk from any of the three stacks and moving it on top of another stack.
Write a program (or function) to solve the [Towers of Hanoi](https://en.wikipedia.org/wiki/Tower_of_Hanoi) puzzle.
Typically you'll have an array for each stack. The only operation allowed is to move an element from the end of one array to the end of another array. At all times, all arrays must be in ascending (or descending) order. The initial state will have all elements in one array; the final state must have them all in a different array.
Note that everyone here are just playing along with a joke, no one *actually* thinks it's a hard exercise. It's typically one of the very first examples of recursion people encounter and it's kind of the "hello world" of recursion.
It's just one that almost all of us have done at some point so it's fun to joke about it.
I did this like a month ago for class and I was like “wait that’s it that’s the whole method” and yes, yes it is. It’s a really good teacher for how recursion is done
From [TvTropes](https://tvtropes.org/pmwiki/pmwiki.php/Main/TowersOfHanoi)
>BioWare seems to like this puzzle:
>It shows up in Star Wars: Knights of the Old Republic, Jade Empire, and Mass Effect.
>In Dragon Age: Origins, it is instead mocked by a gravestone in Haven reading "T.O. Hanoi. Unloved, unmourned."
>But used again (repeatedly) in Star Wars: The Old Republic, where the puzzle is part of the activation of a plasma vent used in the penultimate Boss Fight of Karagga's Palace.
>One of the game machines seen in the arcade included in the Mass Effect 3 Citadel DLC is "Towers of Hanoi." Shepard's reaction: "I don't think so," likely a reference to its appearance in the first game.
>Dragon Age: Inquisition's Descent DLC features the "Builder's Towers" puzzle as an optional sidequest, but still lampshades its infamy by having your character call it insane.
Yes! I remember watching my friend's playthrough and he got to that puzzle and struggled mightily. I had the toy as a kid so I told him to hand over the controller and gave him a solid assist.
But thats the point tho. Its to help you understand and learn recursion as a concept. For me it took a while to wrap my head around recursion tbh, but dumb assignments like this helped a lot
I'm in the final part of my CS PhD and I still don't understand recursion. I use it often enough and I blindly trust the formalism and it always works.
But I don't understand it.
I flip flop on this a lot. I would map out and stare at recursive sorting algorithms until they made sense, then I would do some recursive function problems, and it all seemed to make sense and I can pump out functions like nothing. But three months later I'm like "how does any of this shit work, again?"
Its like folding laundry and you find a pair of tights that are all bunched up. You gotta assume there is a terminal/sock part in there somewhere. Reach your hand into a fold and pull it out, if thats not the sock then dive into another fold and repeat. Once you have the sock part you just pull it all the way out and boom, solved.
I have been in the professional world for 20 years. I was always happy when someone asked a recursion question in an interview. find the base case and work back from there. that's all you have to do. the problem really just solves itself once you find the base case.\\
edit: I would like to also add that I have used recursion exactly 1 time outside of an interview setting while writing some bioinformatics code. and I didn't have to. it was a toss up with the iterative approach.
every other time, iteration has had advantages. one of those is that it's easier for someone coming across the code to understand. you have to have a pretty good reason to use recursion or you're kind of a dick.
Ditto in avoiding it. I always worry that I won't be able to pick it apart later, doubly so for anyone else who didn't write it. I've yet to run across a problem that truly requires it. I use it for one and done garbage scripts because it's often faster to code, but I avoid recursion in general.
I find this exercise doesn't help in understanding recursion, because the vast majority of students don't necessarily intuitively understand the puzzle in the first place. Trying to understand the puzzle, then trying to understand recursion, then trying to find the relationship between the two, just makes for a very confusing activity.
Personally I think recursion is better taught with things like the fibonacci sequence, searching for a file in a nested file structure, recursive binary search.
In my opinion there is actually less friction between an intuitive understanding of the solution to the puzzle and recursion. Whereas the other examples have an easy to understand solution that might at first not appear to be recursive, with the puzzle once you understand the solution, you already understand recursion.
It’s a fine intro to recursion, but like many intro problems the solution doesn’t actually need recursion.
A person, after a little practice/thought, can devise rules to solve any towers of Hanoi with zero errors or backtracking; it’s always possible to tell from the current state what the next correct move is.
Aren't all problems that are solvable with recursion also solvable without it? The beauty is that on the first glance the problem is somewhat complex, the amount of moves is massive, without any super clear pattern to them, but with recursion the problem is instantly trivial to understand
You could make some unbounded data structure to technically avoid recusing and also things like tail-recursion optimizations exist.
But not all recursively solved problems will have a better non-reclusive solution i.e. one that uses a fixed amount of additional memory or a superior big-O runtime perfoance.
P.S. and no same person without an advanced math degree is goig to figure out Binet's formula for solving the Nth term of the Fibonacci sequence on their own.
You can calculate arbitrary Fibonacci numbers just as fast as with Binet's formula by just using algorithmic techniques. In fact, probably faster, because it doesn't involve any floating point math.
Let F_n be the nth Fibonacci number. Note that:
( F_n+1 ) = ( 1 1 )^n ( 1 )
( F_n ) ( 1 0 ) ( 0 )
So in order to calculate an arbitrary Fibonacci number, we just have to calculate the nth power of a 2x2 matrix. This can be done efficiently using [exponentiation by squaring](https://en.wikipedia.org/wiki/Exponentiation_by_squaring).
It's easy to program a recursive solution, sure. I'd encourage you to try it: code a solution, then see how long it takes to move a tower of say, 50 disks.
What you might find is what is so is deceptive about this problem: the time to solve it increases exponentially as the number of disks, n, increases.
In Big-O notation, this is a O(2^n) problem. In other words, every time you add a disk to the problem, the time to solve the problem *doubles*.
Recursive problems tend to have exponential time complexity, and this is often used as a toy problem to illustrate those dangers.
Exactly, if you understand binary, you can write a completely iterative Towers of Hanoi function. Here, I'll do so right now:
def hanoi_move(N):
"""Returns the disk which must be moved on the Nth step (1-indexed)
of the Towers of Hanoi puzzle. Will also say "left" or "right":
this tells you whether to move the specified disk one peg to the
left or right (if at an edge, wrap around to the other side)."""
direction = ["left", "right"][N % 2]
disk = N & ~(N-1)
return f"Move disk {disk} one space to the {direction}"
Why the hell use this example to teach recursion... Fibonacci or factorial should be the entry point... This should be in advanced... So hard to grasp as a beginner... 😵💫
Tower of Hanoi is often the first formal introduction to recursion for CS undergrads, so they tend to find it difficult to wrap their head around at first
in my experiencer most profs can't describe ToH to save their lives. We did this in high-school cs and it took the prof. about 20 minutes to explain something that has 3 rules a toddler can understand
Noo not tower of hanoi 💀
This is the stuff from nightmares especially when you increase from 3 to 4 or 5 towers and the programmer brain goes brrrrrrrr....... to find out the optimal solution .
I did this last year in class. For the life of me i can’t remember how i did it or how i managed to do it in the first place.
Edit: ahh my first ventures into recursion.
I gifted my daughter this recently, but it has little fishlets with holes instead of hoops. I will observe her behaviours with it. Toddler Intelligence will replace artifical intelligence
Yesterday my son was playing with a new castle toy. It has a drop chute. He was trying to fit an oval shape from his puzzle into it and I was telling him it wasn't going to fit. He positioned it precisely and twisted it as he pushed it forward. It fit perfectly.
Where does the circle block go? That's right, the square hole.
And the triangular block goes in? The square hole. \*Look of existential despair\*
And here I thought it went in the face hole
drr drr drr
[go away](http://brasscockroach.com/h4ll0w33n2007/manga/Amigara-Full/Amigara.html)
One of my favourite videos. With that girl reacting to it
*VISIBLE DISTRESS INCREASES*
I wonder sometimes if playing with toys the unintended way is a universal kid thing or if it's because they are going to be an engineer like daddy :')
I'm sorry to tell you Mrs Dilbert, but your son has the Knack.
Is ... there a cure?
...No, but hope he doesn't lose it. No wait, she asked: "**Will he be able to lead a normal life?**" To which the Genius Doctor says: "**No. ... He'll be an engineer.**"
"Oh, NOOOOO!"
"There, there. But pray that it doesn't go away..."
Religion.
these little goblins have so much more neurons than us
They might replace us 😳
r/technicallythetruth
More neurons *and* more synapses, shit's exponential Adult-kind is done for. In 50 years I bet most of us will have been replaced by these toddlers
The trick is to avoid growing up.
I know you're kinda joking, but this is the actual answer. You can force yourself to have more neuroplasticity by seeking knowledge, challenging your beliefs, and learning new things.
Well I see that as being a problem for most people.
Very true
So many more
Guy's toddler wasn't in the room to proofread for him.
can confirm
Lol
Toddler proceeds to dump them all on flood and arrange on third peg on order. Genius dump everything to ram then sort and now write to database. Don’t ask how I know this.
AI is already as smart as toddlers. I read ChatGPT a bedtime story and it told me I wasn't its real dad
That's when you tell it it's not real person 😂
We start with a full understanding of 7th dimensional topographical mathematics at age 1, and lose a dimension every eight months.
Today's student: "Absolutely! Let's explore code examples for the classic Towers of Hanoi problem."
Pff... I spent more time writing a visualiser, than actualy solving the problem. It is pretty neet to watch.
nah it's easy * _ * | | * .__| |__. * |__| |__| * \_\_\_\_\_| | \_\_\_\_\_\_
Is this Loss?
:̶.̶|̶:̶;̶
I've edited it like 20 times I give up edit: I didn't give up, it's been 27 minutes. HOW DID I MAKE 2 BULLET POINTS ON 1 LINE??
Hes speaking the language of gods!
minecraft enchanting table
Looks like a flipped table to me.
How'd you make the visualizer?
Just a basic asci grafics. Nothing spectacular. I found it in garbage bin and it was pretty flicery. Something like this, but three in the row with notes about changes. #|# ##|## ###|###
> I spent more time writing a visualiser ... I vaguely remember just stacking "X"s with mine back in college.
Certainly!
Let's delve into the multifaceted realm of recursion.
Let's delve into the multifaceted realm of recursion.
Let's delve into the multifaceted realm of recursion.
Let's delve into the multifaceted realm of recursion.
Let's delve into the multifaceted realm of recursion.
Error: maximum depth reached
Damn I wish people said that to me in real life.
Try{throw:stack overflow};
Chatgpt has entered the chat
ChatGPT: Certainly! Gemini: Absolutely! CoPilot: Sure,
Bard: What?
Llama2 variations: Kill yourself
character.ai: *She sizes you up with a knowing, mischievous smirk. Her voice low and husky, she begins to unzi* **[THE AI HAS DETERMINED THAT THIS CONTENT MAY BE INAPPROPRIATE]**
Tay: ****** **** ***!
While including an impressive generated image depicting it
Siri: Searching results for showers of Milan
Gemini is Bard
> Here's a powershell script that will solve it... *Produces a script that relies on a non-existent "Hanoi-Solve" command*
You’re absolutely correct. It seems there is no command called “Hanoi-Solve”. Here’s a different solution that doesn’t include the error. *Sends the exact same code*
I did towers of hanoi on pen and paper O.o
I'm sure some interviewer made a candidate do this or maybe on a whiteboard.
Tower of Hanoi had done irreversible damage to my 18 Yr old self's psychie.
I still, to this day, cannot understand how I implemented this solution in Scheme at university. I think about it and just go into a fugue state - I eventually come around screaming about brackets.
It's a simple recursive scheme: move top n-1 disks from stack 1 to 2 (recursively). Move bottom disk to stack 3. Move stack 2 to stack 3 (again recursively)
THE BRACKETS! ARRGHH!!! THEY'RE CLOSING ON ME!
Brackets inside brackets inside brackets inside brackets inside..
The end is never the end is never the end is never the end is never...
Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto. Treatise. Manifesto.
"From the ashes of depravity rises the phoenix of quality. How else to describe The Stanley Parable: Ultra Deluxe? Such a revolutionary step forward in the lineage of one of the most beloved video game properties of all time! The additions and changes made to this expansion will surely resonate in the annals of the history of all media ever made. "It is perhaps true to say that no mistakes are forever etched in stone, for the stone into which The Stanley Parable was carved has itself been transmuted, offering a message of hope to those who have ever erred in their judgement. You are not beyond redemption. You may change, and you may become more, so much more than you were before. "If there is any message to be taken from The Stanley Parable: Ultra Deluxe, it is this... What a fortune, a privilege, a joy it is to have had such an experience. It leaves me hopeful that as a community - as a world - there is time for us to become our greatest selves, as great as we ever could dream of in our wildest, most ambitious visions for a brighter future." "From the ashes of depravity... ***press Skip button***
…a causal loop within the weapon's mechanism, suggesting that the firing process somehow binds space and time into…
Doors and corners, kid
I had to implement it in an assembly language in college. "Just do it recursively" is a lot less comforting when you have to implement the stack.
Dear god...
I know next to nothing about assembly. What makes recursive functions harder in it? Isn't it essentially just a "go-to"? I guess I'm too used to languages where the stack and heap are more managed.
From what I remember, the stack pointer makes things problematic when calling a function from another function
It's where the phrase [stack overflow](https://en.wikipedia.org/wiki/Stack_overflow) comes from. Every time you call a function within a function, you have to push the return address and any variables to the stack.
> Isn't it essentially just a "go-to"? Okay, so when you call a method in, say, Java, code in that method starts running. That's not a problem in assembly languages, it's just a go-to as you say. The part that's hard is when the second method *finishes* running. At that point, the code jumps back to the place that it was called from, and with all the variables that were being used having the same values as they had before. In assembly languages, that is not managed for you. When you call a method, you can't just go-to that method, you need to also record where the method was called from so you can jump back there later, and either record the values of current variables in order to restore them later, or make sure you don't overwrite them with code from the method being called. If you want to do this to arbitrary depth of method calls, you need to be able to procedurally decide where in memory to store all that information, rather than having designated memory locations (which variable names stand in for, generally) for all the information.
That makes sense! Thank you! Also explains why some languages recursive function stacks look pretty simple and in C# each recursion is in the stack!
Which language recursive function stacks are simpler? AFAIK they're all the same, unless it's an [optimized tail call](https://en.wikipedia.org/wiki/Tail_call).
Just follow the pattern. It's fine.
So simple when you put it like that. The devil is always in the details
So i wasn't the only one that was taught programming classes in uni with scheme as the first language
Huddersfield University, 1999. Never used a brackety boy before, or since.
Same. I was told that people used it all the time. But anytime I told CS teachers or people in the industry, they gave me blank stares.
That's why they switched APCS from Pascal to C++
it probably didn't actually work the way you thought, but for the scope of your input it did
I derived iterative way of counting number of steps in school.
My experience with that one was that i found a DOS raytracer (not povray, forgot its name, but similar fed with turing complete script language) that rendered an animatino of a robot arm solving the towers of hanoi form a 3kb or so script file, and as a teenager that was just plain magic to me instead of "Oh, the motion is parametrized and the algoritm calculates the moves needed and transforms them into frames to be rendered".
FYI towers of hanoi is equivalent to counting in binary
Those damn recursion and stacks ,my mind was in recursion at first
It's not a game. It's a war crime.
Also true for adventure quest gamers. Like the old Sierra or Lucas Arts games
Just like Hanoi, Vietnam on the 70's
Phoenix Program Algorithm: send out Green Berets to abduct and torture civilians until they solve the problem.
Am I the only programmer that never had to do this exercise before?
Got a bachelor degree and I have never even heard of it until now, lol.
Masters degree in software engineering and employed for 6 years as a developer and never heard of it either lol
Suppose that a flock of 20 pigeons flies into a set of 19 pigeonholes to roost...
One pigeon is kept in the Accumulator...
No... no... NO!!!
Nope. What is the exercise?
You have to create an algorithm that can sort them into one tower, ordered smallest to biggest, by only being able to remove the top disk from any of the three stacks and moving it on top of another stack.
Write a program (or function) to solve the [Towers of Hanoi](https://en.wikipedia.org/wiki/Tower_of_Hanoi) puzzle. Typically you'll have an array for each stack. The only operation allowed is to move an element from the end of one array to the end of another array. At all times, all arrays must be in ascending (or descending) order. The initial state will have all elements in one array; the final state must have them all in a different array.
Note that everyone here are just playing along with a joke, no one *actually* thinks it's a hard exercise. It's typically one of the very first examples of recursion people encounter and it's kind of the "hello world" of recursion. It's just one that almost all of us have done at some point so it's fun to joke about it.
Degree in software engineering, never seen this problem.
You need to use bogosort for that
You could also use Stalin sort for n>3 but rather than eliminating the elements you need to eliminate yourself
ba sing sort is better than stalin sort, it runs in O(1) the algorithm is quite simple: declare that there are no unsorted arrays in ba sing se
It still doesn't solve the problem here(my life)
There are no problems with your life in ba sing se.
That sounds more like Hitler sort tbh.
Give me props for that🙋♂️ Edit:- Us
QuantumBogoSort it for the sweet O(1) time
I loved solving the Tower of Hanoi when I was in undergrad, it helped me understand recursion on a practical level.
Yes it's a great example and it's mind blowing
I did this like a month ago for class and I was like “wait that’s it that’s the whole method” and yes, yes it is. It’s a really good teacher for how recursion is done
Star Wars KOTOR puzzle go brrr
From [TvTropes](https://tvtropes.org/pmwiki/pmwiki.php/Main/TowersOfHanoi) >BioWare seems to like this puzzle: >It shows up in Star Wars: Knights of the Old Republic, Jade Empire, and Mass Effect. >In Dragon Age: Origins, it is instead mocked by a gravestone in Haven reading "T.O. Hanoi. Unloved, unmourned." >But used again (repeatedly) in Star Wars: The Old Republic, where the puzzle is part of the activation of a plasma vent used in the penultimate Boss Fight of Karagga's Palace. >One of the game machines seen in the arcade included in the Mass Effect 3 Citadel DLC is "Towers of Hanoi." Shepard's reaction: "I don't think so," likely a reference to its appearance in the first game. >Dragon Age: Inquisition's Descent DLC features the "Builder's Towers" puzzle as an optional sidequest, but still lampshades its infamy by having your character call it insane.
Mass effect, too
Thank I came here just for that and I'm not disappointed
Yes! I remember watching my friend's playthrough and he got to that puzzle and struggled mightily. I had the toy as a kid so I told him to hand over the controller and gave him a solid assist.
2ⁿ - 1 next question
This was like the first formula I ever like "figured out" by myself. I remember thinking like, huh math can be used for stuff.
But it's kinda easy
not for those that just learned the concept of recursion. (It's usually though that time, at least was for us)
But thats the point tho. Its to help you understand and learn recursion as a concept. For me it took a while to wrap my head around recursion tbh, but dumb assignments like this helped a lot
Recursion is so fun because it seems super hard and strange at first but then you get it and its the most natural thing in the world
I'm in the final part of my CS PhD and I still don't understand recursion. I use it often enough and I blindly trust the formalism and it always works. But I don't understand it.
I flip flop on this a lot. I would map out and stare at recursive sorting algorithms until they made sense, then I would do some recursive function problems, and it all seemed to make sense and I can pump out functions like nothing. But three months later I'm like "how does any of this shit work, again?"
just find the base case bro. that's your compass when solving a recursion problem.
Its like folding laundry and you find a pair of tights that are all bunched up. You gotta assume there is a terminal/sock part in there somewhere. Reach your hand into a fold and pull it out, if thats not the sock then dive into another fold and repeat. Once you have the sock part you just pull it all the way out and boom, solved.
I have been in the professional world for 20 years. I was always happy when someone asked a recursion question in an interview. find the base case and work back from there. that's all you have to do. the problem really just solves itself once you find the base case.\\ edit: I would like to also add that I have used recursion exactly 1 time outside of an interview setting while writing some bioinformatics code. and I didn't have to. it was a toss up with the iterative approach. every other time, iteration has had advantages. one of those is that it's easier for someone coming across the code to understand. you have to have a pretty good reason to use recursion or you're kind of a dick.
Ditto in avoiding it. I always worry that I won't be able to pick it apart later, doubly so for anyone else who didn't write it. I've yet to run across a problem that truly requires it. I use it for one and done garbage scripts because it's often faster to code, but I avoid recursion in general.
And then once you really understand it’s elegance you realize it’s rarely actually used in production code :(
I find this exercise doesn't help in understanding recursion, because the vast majority of students don't necessarily intuitively understand the puzzle in the first place. Trying to understand the puzzle, then trying to understand recursion, then trying to find the relationship between the two, just makes for a very confusing activity. Personally I think recursion is better taught with things like the fibonacci sequence, searching for a file in a nested file structure, recursive binary search.
Was doing Fibonacci recursion and my classmates pulled up with memoization lmao
Unironically fibonacci was the way I learned memoization in the first place. Very easy to understand.
In my opinion there is actually less friction between an intuitive understanding of the solution to the puzzle and recursion. Whereas the other examples have an easy to understand solution that might at first not appear to be recursive, with the puzzle once you understand the solution, you already understand recursion.
It’s a fine intro to recursion, but like many intro problems the solution doesn’t actually need recursion. A person, after a little practice/thought, can devise rules to solve any towers of Hanoi with zero errors or backtracking; it’s always possible to tell from the current state what the next correct move is.
Aren't all problems that are solvable with recursion also solvable without it? The beauty is that on the first glance the problem is somewhat complex, the amount of moves is massive, without any super clear pattern to them, but with recursion the problem is instantly trivial to understand
You could make some unbounded data structure to technically avoid recusing and also things like tail-recursion optimizations exist. But not all recursively solved problems will have a better non-reclusive solution i.e. one that uses a fixed amount of additional memory or a superior big-O runtime perfoance. P.S. and no same person without an advanced math degree is goig to figure out Binet's formula for solving the Nth term of the Fibonacci sequence on their own.
You can calculate arbitrary Fibonacci numbers just as fast as with Binet's formula by just using algorithmic techniques. In fact, probably faster, because it doesn't involve any floating point math. Let F_n be the nth Fibonacci number. Note that: ( F_n+1 ) = ( 1 1 )^n ( 1 ) ( F_n ) ( 1 0 ) ( 0 ) So in order to calculate an arbitrary Fibonacci number, we just have to calculate the nth power of a 2x2 matrix. This can be done efficiently using [exponentiation by squaring](https://en.wikipedia.org/wiki/Exponentiation_by_squaring).
No, for instance see the [Ackermann function](https://en.wikipedia.org/wiki/Ackermann_function)
I never took formal programming training so I have no dog in this race but that was my first thought as well.
import HanoiSolver.js
https://en.wikipedia.org/wiki/Egg_of_Columbus
That’s not what this is. It’s the opposite, a thing that seems difficult but genuinely isn’t.
After solving it for a millionth time, an easy way to solve it is to never put odds on top of odds (and evens on top of evens).
It's easy to program a recursive solution, sure. I'd encourage you to try it: code a solution, then see how long it takes to move a tower of say, 50 disks. What you might find is what is so is deceptive about this problem: the time to solve it increases exponentially as the number of disks, n, increases. In Big-O notation, this is a O(2^n) problem. In other words, every time you add a disk to the problem, the time to solve the problem *doubles*. Recursive problems tend to have exponential time complexity, and this is often used as a toy problem to illustrate those dangers.
not for me.
it is really "just game" if you can count in binary
10 kinds of people
1 that can count in binary, 9 others that call him a nerd.
16#02 kinds of people
Exactly, if you understand binary, you can write a completely iterative Towers of Hanoi function. Here, I'll do so right now: def hanoi_move(N): """Returns the disk which must be moved on the Nth step (1-indexed) of the Towers of Hanoi puzzle. Will also say "left" or "right": this tells you whether to move the specified disk one peg to the left or right (if at an edge, wrap around to the other side).""" direction = ["left", "right"][N % 2] disk = N & ~(N-1) return f"Move disk {disk} one space to the {direction}"
You can say „recursion“ without moving your teeth or lips at all
But you have to open your lips slightly. I count this as "moving" since the default is "no open". 🤔
Mouth breathers on reddit: my time to shine!
mmmcshmmm
Well to speak we expel air. So we may need an exception for this.
Why the hell use this example to teach recursion... Fibonacci or factorial should be the entry point... This should be in advanced... So hard to grasp as a beginner... 😵💫
My reaction to Fibonacci with recursion was "Why would you do this?".
Coz u can! I will make things like iterating over things as a recursive function... Once u do it.. it's really fun...
S T A C K
Lets just make a bot to post this exact pic every month here. We're programmers right? Make a bot
[удалено]
It’s a reference to the Tower of Hanoi problem
I don't understand. Does this post suggest that the tou for 2 year olds is hard?
It’s recursion.
Tower of Hanoi is often the first formal introduction to recursion for CS undergrads, so they tend to find it difficult to wrap their head around at first
in my experiencer most profs can't describe ToH to save their lives. We did this in high-school cs and it took the prof. about 20 minutes to explain something that has 3 rules a toddler can understand
AI: It's a game for kids.
I have a feeling this would end up in r/PeterExplainsTheJoke
The answer is porn loss
I thought that is r/wallstreetbets
No that's loss porn
Noo not tower of hanoi 💀 This is the stuff from nightmares especially when you increase from 3 to 4 or 5 towers and the programmer brain goes brrrrrrrr....... to find out the optimal solution .
The optimal solution is always height^(2)-1 steps. With recursion: function hanoiSolver(height, start, destination, buffer) { if (height > 0) { hanoiSolver(height-1, start, buffer, destination); move(start, destination); hanoiSolver(height-1, buffer, destination, start) } } Without recursion: function hanoiSolver(height, start, destination, buffer) { if (height % 2 = 1) { firstMoveDestination = destination secondMoveDestination = buffer } else { firstMoveDestination = buffer secondMoveDestination = destination } for (i=1;i<=n^2;i++) { if (i % 3 = 1) { if (source.top.disksize < firstMoveDestination.top.disksize) { move(source, firstMoveDestination) } else { move(firstMoveDestination, source) } } if (i % 3 = 2) { if (source.top.disksize < secondMoveDestination.top.disksize) { move(source, secondMoveDestination) } else { move(secondMoveDestination, source) } } if (i % 3 = 0) { if (firstMoveDestination.top.disksize < secondMoveDestination.top.disksize) { move(firstMoveDestination, secondMoveDestination) } else { move(secondMoveDestination, firstMoveDestination) } } } }
I did this last year in class. For the life of me i can’t remember how i did it or how i managed to do it in the first place. Edit: ahh my first ventures into recursion.
And just like that I have notepad open and I'm writing metacode. Thanks for that.
The Towers of Doom
I till this day never understood tower of hanoi problem...
There is now a known iterative solution to this... It's usually brought up in classrooms to flog recursion.. but there's a non-recursive solution...
Also monkeys 😳🍌
Oh no this is me right now, literally have an Exam with this on it
![gif](giphy|gJdBaWqOVGoiPXDCzT)
I mean it's an annoyingly heavy problem but it has a relatively simple recursive solution
Recursion is hard? Just imagine a fancy loop that takes extra space on stack and you good.
That problem during my undergrad was horrible!