Тёмный

Binary, Hanoi and Sierpinski, part 1 

3Blue1Brown
Подписаться 7 млн
Просмотров 703 тыс.
50% 1

Binary counting can solve the towers of Hanoi puzzle, and if this isn't surprising enough, it can lead to a method for finding a curve that fills Sierpinski's triangle (which I get to in part 2).
Thanks to Desmos for their help in supporting this video. They're hiring, and anyone interested should check out www.desmos.com...
Thanks to all Patreon supporters as well, you can support and get early access to future "Essence of" series here: / 3blue1brown
I also want to give a special shoutout to the following patrons: CrypticSwarm, Ali Yahya, Dave Nicponski, Juan Batiz-Benet, Yu Jun, Othman Alikhan, Markus Persson, Joseph John Cox, Luc Ritchie, Einar Wikheim Johansen, Rish Kundalia, Achille Brighton, Kirk Werklund, Ripta Pasay, Felipe Diniz, Chris, Curtis Mitchell, Ari Royce, Bright , Myles Buckley, Robert P Zuckett, Andy Petsch, Otavio good, Karthik T, Steve Muench, Viesulas Sliupas, Steffen Persch, Brendan Shah, Andrew Mcnab, Matt Parlmer, Naoki Orai, Dan Davison, Jose Oscar Mur-Miranda, Aidan Boneham, Brent Kennedy, Henry Reich, Sean Bibby, Paul Constantine, Justin Clark, Mohannad Elhamod, Denis, Ben Granger, Jeffrey Herman, Jacob Young.

Опубликовано:

 

2 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 683   
@TheGerogero
@TheGerogero 7 лет назад
How is this the first time I hear that _bit_ is short for _binary digit_... Mind blown.
@zairaner1489
@zairaner1489 7 лет назад
Yeah I needed a moment after that,
@i_cam
@i_cam 7 лет назад
Raphael Schmidpeter same tho
@accuratejaney8140
@accuratejaney8140 7 лет назад
TheGerogero ikr, i counted up to 790 in binary without understanding what bit meant.
@AppleberrySmith
@AppleberrySmith 7 лет назад
TheGerogero same
@evanweaver7373
@evanweaver7373 7 лет назад
Does that mean a digit in the ternary system is... A tit?
@ZardoDhieldor
@ZardoDhieldor 7 лет назад
I simply love your videos! I'm a mathematics student, so I'm used to the joy of understanding, but that doesn't make it any less exciting! And your animations are a wonderful, powerful and beautiful help in this delightful process! I may be repeating myself but nonetheless: Thank you! Keep up the great work! :)
@3blue1brown
@3blue1brown 7 лет назад
Always nice to hear from an enthusiastic math student, and thanks for the kind words. Keep loving math.
@Xappreviews
@Xappreviews 7 лет назад
Same here :) I'm a computer science student, and I love how you visually explain problems, it makes everything a lot easier to understand. I would have had a much harder time understanding this in a textbook, especially the concepts you explained in part 2. I hope that sometime in the future, we will integrate visual material like this into out science lectures
@enotirab
@enotirab 7 лет назад
I am software developer (who also has a love for math) and it never once occurred to me that counting was a recursive action. I am continuously amazed at how elegant and simple your videos are and how effective they are at showing complex ideas in an approachable way. Thanks for all your hard work!
@smolboye1878
@smolboye1878 4 года назад
​@@vairavanrenganathan4752 I don't want to put words in his mouth but I believe that he sort of means self-similar. By that, I mean that you can break it down into scaled down problems that are similar in procedure to solve.
@ultrio325
@ultrio325 3 года назад
same
@dalex641
@dalex641 3 года назад
Any cycle can be represented as a recursive action. Any recursive action can be represented as a cycle.
@azursmile
@azursmile 2 года назад
You might be interested in the Church encoding of numbers in Lambda Calculus which is a mathematical analog to functional / recursive programming (as Turing machines are to imperative languages)
@creusianemoraes6422
@creusianemoraes6422 2 года назад
eəėëėəe
@SendyTheEndless
@SendyTheEndless 7 лет назад
Binary digits? I'd have called them bidgits.
@DoubleBob
@DoubleBob 7 лет назад
"Not lazy enough. Let's shorten it down to bits." --- Computer Scientists.
@PleasestopcallingmeDoctorImath
bigits just didnt have the same ring to it
@jadondavid8272
@jadondavid8272 7 лет назад
SquareWaveHeaven bigots*
@johnnypiquel2295
@johnnypiquel2295 4 года назад
@@jadondavid8272 no
@mariosumilang7556
@mariosumilang7556 4 года назад
I’ve heard of another thing: mijits
@pablocastaneda268
@pablocastaneda268 Год назад
There's something you overlooked at least in this video and that is quite beautiful. The even-numbered disks either move one space to the right or two spaces to the left, and the odd-numbered ones do the opposite: move one space to the left or two spaces to the right. It's determined by the binary number that each disk adds but modulo 3.
@QuantumSeanyGlass
@QuantumSeanyGlass 7 лет назад
You missed the fact that odd numbers are always moved left and even numbers are always moved right.
@henkvdpol
@henkvdpol 7 лет назад
nice catch!
@zombiedude347
@zombiedude347 7 лет назад
Or vice versa. I remember in one of the jump-start CD games, you had to solve this a lot. Except, the location of the final stack mattered. So if you had an odd number of boxes, the first box would move to the location of the final stack. If even total, to the stack you aren't supposed to end up on.
@knockdown79
@knockdown79 7 лет назад
two steps forward, and one step back!
@jamesmaxa3129
@jamesmaxa3129 6 лет назад
Thanky fer ifnooh (why do i write like this)
@KnakuanaRka
@KnakuanaRka 5 лет назад
James Maxa It’s text in a window; you have time to look at it and correct stuff before submitting it!
@Cyanogenoid
@Cyanogenoid 7 лет назад
Wouldn't it make more sense for the binary numbers at 6:05 and 11:20 to be coloured exactly the opposite way they are, i.e. leftmost digit bright blue and rightmost digit dark blue? That way the colour of the digit that flips corresponds to the same colour of disk that's actually moved.
@3blue1brown
@3blue1brown 7 лет назад
Ooh, good catch! What's funny is that I did it right for the ternary counting in the next video. Ah well, silly mistakes have a pernicious way of sneaking into all my videos, you know?
@aditimuthkhod1252
@aditimuthkhod1252 4 года назад
@@3blue1brown So modest!🙇🏻‍♀️
@efulmer8675
@efulmer8675 3 года назад
@@3blue1brown It's the silly mistakes that do not affect the content of the video that much that remind the rest of us that we are in fact listening to an incredibly talented youtuber telling us the wonders of (probably) his favorite subject.
@msfundio
@msfundio 2 года назад
@@efulmer8675 Are you implying Cyanogenoid is not in fact listening? Of course they are.
@efulmer8675
@efulmer8675 2 года назад
@@msfundio No, I'm not suggesting that at all.
@EmilMacko
@EmilMacko 6 лет назад
I've used Desmos for a little over a year now, and I'm sad that my math classes never use it. I mainly just use it for my game development and for math-fun. It's the best math-function graphing tool I've ever used.
@maximkazhenkov11
@maximkazhenkov11 7 лет назад
Fun trivia: According to legend, when the full 64 disc puzzle is solved, the world will end. Assuming 1 move per second, it would take 2^64-1 = 1.84*10^19 seconds or 585 billion years, which is incidentally the time it takes until the last star in the universe burns out.
@shreeganesh441
@shreeganesh441 5 лет назад
Program it and it'll be done very soon.
@NoobieToob
@NoobieToob 5 лет назад
1 move per second is way too slow (for a computer).
@bhanuprakash9746
@bhanuprakash9746 5 лет назад
True... True
@RipleySawzen
@RipleySawzen 5 лет назад
A red dwarf's lifespan is EASILY into the trillions of years. So your anti-science fact is false.
@bhu1334
@bhu1334 4 года назад
@@shreeganesh441 use delay(1000)
@Patrick_Bard
@Patrick_Bard 7 лет назад
Man, I really appreciate your videos. I must say that I a computer scientist of sorts (Information Systems actually) so binarry is no problem for me and that I loved Tower of Hanoi since I first saw it. So normally to solve the puzzle, I just look if the the ammount of disks, check if it's odd or even to tell the direction of cycle I'll do with the smaller disk, left or right repectvly. Then I just know that I must start moving the smaller according to the cycle, after that, do an obrigatory move, moving smaller, obrigatory move, and so on. Even though I know exactly the logic of how to do it in the most efficient way, I never saw any connection of the puzzle and the rhythm of bynary counting as you showed. I was simply amazed. Thank you, keep doing this amazing work for us.
@carab3201
@carab3201 7 лет назад
Oh man, I know desmos was a sponsor of this video, but I gotta say, I'm a computer engineering university student, and I use the graphing app from them all the time. I do some very complicated mathematics most of the time, and it's really helpful to be able to put a complicated function in and add some parameters as sliders to see how it affects the shape of the graph. I actually just used it the other day and noticed they added integrals, and I was super excited to see that. On a more related note, this video was excellent. I took an algorithms class in which we studied towers of hanoi solving methods. However, my professor didn't really show the connection between the recursive algorithm and counting in binary. Really insightful stuff.
@CraaaabPeople
@CraaaabPeople 7 лет назад
Your channel is absolutely gold dude. Keep up the good work. It's so refreshing to see university level mathematics displayed so entertainingly and so clearly. Thank you.
@caribreeze
@caribreeze 6 лет назад
tower of hanoi puzzle is pretty neat. i had to write a recursive method in java that would "solve" the puzzle recursively for any amount of discs. the craziest thing was how much time it took for the compiler when you added a crazy amount of disks like 20 or 50.
@myrus5722
@myrus5722 6 лет назад
Great video you explained everything so well I could feel why counting in binary works in a way others haven’t been able to do.
@nin10dorox
@nin10dorox 7 лет назад
This one was incredible! the math was really cool and the animations were insane! and you're supported by the best graphing calculator ever!!!
@fossilfighters101
@fossilfighters101 7 лет назад
+
@intellectualize6354
@intellectualize6354 5 лет назад
You probably meant "you ARE the best graphing calculator ever".
@SongSeeker7
@SongSeeker7 7 лет назад
Interesting video! I tried a little experiment. In the unrestricted case If there are 3 stones stacked on top of each other labeled 0, 1, and 2, then the next column position of the rock represented by a trit change can be calculated by 3^label modulo columns. I tried this with 4 columns and it works out, but for 3 or 5 columns, the direction of the move toggles left and right.
@pqnet84
@pqnet84 6 лет назад
Here is a nice argument about towers of Hanoi, that I think it's pretty trivial but i never see people talking about it: At any valid position in towers of hanoi you have at most 3 valid moves: moving disk 0 on any of the other two pegs and (if at least one of the two other pegs are populated) moving the smallest disk in other pegs. In the ideal solution you never move the same disk twice in a row (because you could just move it once in the right position in the first place), so for odd numbered moves you move disk 0, for even numbered moves you move whatever else is available, in the only available place. The disk you have to move is always forced by this simple argument of "not doing useless moving around": counting in binary, or thinking about recursion does not give useful information to solve the problem (but helps to figure out the total number of moves, see below), because the only choice we have to make is "where do I have to put disk 0 now?" The only "solution" part of the video is thus "always move disk 0 to the right". Or always to the left, depending on where you want to end up in: the total number of moves you have to do is 2^number of disks - 1 (which can easily be deduced from both binary and recursive description above), and the first and last moves are thus moves of disk 0. With a simple modulus 3 operation you realize which peg you end up in: with an odd number of disks your last move will be toward the same peg as your first move, with an even number of disk you will end on the other peg instead. Indeed all disk will move in a rotating fashion in the final solution, in alternating directions: if you move disk 0 to the right disk 1 will move to the left, disk 2 again to the right and so on. This will give you a hint on where the biggest disk, which is moved only once, will end up accordingly to the direction you choose for disk 0. If your goal is to print the sequence of moves without having the actual puzzle then counting in binary will indeed help. But then you need an argument to figure out in which disk the peg is from the binary number: I'll add one here. Since the direction disk moves is easily predictable, you only have to count how many time each disk has been moved: in the binary representation this happens every time you flip its digit to 1, that is you can toss away the least significant digit and divide the number you obtain by two, approximating by excess. Example: if your count is 010011001 and you want to know how many time disk 4 has been moved, you can throw away 4 least significant digits (you don't care where disks smaller than it are) and get 01001, which is 9. This mean up until now you moved disk 4 and bigger 9 times, of which the odd moves disk 4 was moved, even moves you moved a bigger disk (you don't care which one now). Disk 4 has thus been moved 5 times, and thus it did almost one full rotation. As disk 4 is even it moves in the same direction of disk 0, hence if you move disk 0 to the right disk 4 is currently in the C peg, if you move it to the left it is in the B peg.
@your_future_self
@your_future_self 7 лет назад
I just realized that 2048 was just making us count in binary
@JM-lh8rl
@JM-lh8rl 7 лет назад
MrLusass Well, decimalized binary
@goffe2282
@goffe2282 7 лет назад
You should check out Threes. 2048 plagiarised that game pretty heavily and is not nearly as deep and compelling. It has a very similar principle but is more complicated.
@raffimolero64
@raffimolero64 6 лет назад
really, you just noticed that now
@birthsonbluebell3654
@birthsonbluebell3654 6 лет назад
When will there be a game that is using base 1? Base 1 is my favorite base
@RenanPeris
@RenanPeris 5 лет назад
@Johnny Lee Does he have no fingers?
@p2beauchene
@p2beauchene 2 года назад
So nice ! I taught the Hanoi towers when I was teaching algorithmics, because it was the simplest example I could think of with exponential complexity, but I never knew this trick with binary counting ! There is an error in the transcript at 7:55 : the number of steps required is 2^n - 1, not 2^(n-1).
@trudyandgeorge
@trudyandgeorge 7 лет назад
Your channel is lovely. a fantastic corner of RU-vid.
@ollipaukkeri
@ollipaukkeri 5 лет назад
I think you could have highlighted the fact that you are moving the piece one right, and if you can't move it one right, two right. Moving straight left in the animation, in the case of skipping over from the middle position or the rightmost position, had me confused for a while. This mechanic also neatly explains why the piece moving can never move back onto the piece that was "trying to get rid of it", which was what I didn't originally understand. Great video though! Thanks!
@ilonachan
@ilonachan 5 лет назад
Wow, just solved a programming task for the Towers of Hanoi, and remembered that this video existed. Thanks for saving the day _and_ blowing my mind.
@dddtl
@dddtl 7 лет назад
I really like your use of the Computer Modern typeface!
@zachallen6256
@zachallen6256 4 года назад
Your videos captured my attention so well in your calculus lectures, that I finally dispelled the notion that I was not a math person, and simply needed to try harder. Finally going back to school, and no longer avoiding math intensive fields! Seriously though, this video is so cool, my girlfriend generally isn’t interested in this kind of stuff, but she loved this as well. Thank you, for working hard to put this stuff out.
@anson7064
@anson7064 4 года назад
I have been struggling with finding the best strategy for this game and you revealed it!!! :O
@denmartorlanda
@denmartorlanda 7 лет назад
There are 10 types of people in the world: Those who understand binary. Those who don't, And those who were'nt expecting a ternary joke.
@pietervannes4476
@pietervannes4476 5 лет назад
And those who think these jokes are getting old (even with base 3)
@thehiddenninja3428
@thehiddenninja3428 5 лет назад
This joke is phrased wrongly because the set of those who weren't* expecting a ternary joke is not mutually exclusive to the first two sets. In fact, since the first two sets are exhaustive, so you have 4 sets: those who don't understand binary and were not expecting a ternary joke those who do understand binary and were not expecting a ternary joke those who do understand binary and *were* expecting a ternary joke those who don't understand binary and were expecting a ternary joke. It happens that the last set is almost completely empty, so you can assume there are 10 (in ternary) non-empty subsets of people, but it means the joke is illogical
@happyfakeboulder644
@happyfakeboulder644 5 лет назад
@@thehiddenninja3428 r/whooshverysmart?
@mr.champion7304
@mr.champion7304 4 года назад
It even rhymes quite nicely
@shagarakar
@shagarakar 4 года назад
Happy Fakeboulder don’t use reddit garbage on youtube.
@VaraNiN
@VaraNiN 7 лет назад
A simpler rule (only needing to count in base ten (or not at all when you got into the rythm) I noticed when trying this out: - On an odd numbered move: Move the 0-piece once to the right (or left, works both ways as long as you dont switch direction) - On an even numbered move: Move the largest piece you can move (which is never the 0-piece) to the only legal place Which is, of course the same as counting in binary, but a little simpler to put to use imo :)
@kayleighlehrman9566
@kayleighlehrman9566 6 лет назад
another great perspective that I just realized...count up how many times each disc /has/ to move, starting from the bottom. disc n has to move just once, disc n-1 has to move twice (once to get off of disc n and once to get back on again), disc n-2 has to move four times, etc
@tomoakhill8825
@tomoakhill8825 4 года назад
I saw this puzzle 50 years ago in high school. My classmates were struggling with it. I just sat down and did it without hesitation. It has always been obvious to me. I earned a Masters Degree in Computer Science. It seemed to me trivially obvious that this puzzle was binary counting. 3Blue1Brown explains this beautifully.
@yaeldillies
@yaeldillies 6 лет назад
I always felt like counting in binary when solving towers of Hanoi! That's amazing now that I understand why.
@lloydsadofsky8411
@lloydsadofsky8411 7 лет назад
If I were to put counting in binary into a memory based way, rather than a function, I would tell you this; For every iteration the 1's place digit changes, for every two iterations the 2's digit changes, for every four iterations the 4's digit changes, and so on. I have always been amazed by the infinite number of distinct patters in binary. 1 001 2 010 3 011 4 100 5 101 6 110 7 111
@morgengabe1
@morgengabe1 7 лет назад
Once in year 7 or 8 I was in maths and at the end of the class the teacher asked the class how we could improve our understanding of the content covered in class that day. Some students suggested things like calculating the cost and change (if paid in cash) of grocery expenditure. Another said "counting" and the teacher laughed, and said "counting what?", the student said "anything", the teacher laughed again but louder and with the rest of the class before saying "No [name], I don't think counting is going to help". Looks like counting is pretty useful right about now.
@nagys36snn
@nagys36snn 5 лет назад
Could be s specific question
@shivamraina2786
@shivamraina2786 5 лет назад
R
@borekworek69
@borekworek69 5 лет назад
Cool profile pic
@snowfloofcathug
@snowfloofcathug 7 лет назад
I never thought about it, I just found it so simple once I found the pattern, but I never could've imagined it'd be hiding something more complex and so beautiful
@luizdemilon
@luizdemilon 7 лет назад
Your visuals keep getting better! Nice!
@SaveSoilSaveSoil
@SaveSoilSaveSoil 2 года назад
"Counting is self-similar" -- fantastic and thought provoking!
@cbranalli
@cbranalli 7 лет назад
i believe the recursive subroutine at 9:52 could use a return statement at the end (although it may be inferred by the compiler ?) with disks 3 2 1 and 0 pre-stacked on PEG A - this subroutine generates the following sequence of directives (d = decimal notation / b = binary notation) A 3210 B C STATE 00d = 0000b MOVE DISK 0 (from PEG A to PEG B inferred) A 321 B 0 C STATE 01d = 0001b MOVE DISK 1 (from PEG A to PEG C inferred) A 32 B 0 C 1 STATE 02d = 0010b MOVE DISK 0 (from PEG B to PEG C inferred) A 32 B C 10 STATE 03d = 0011b MOVE DISK 2 (from PEG A to PEG B inferred) A 3 B 2 C 10 STATE 04d = 0100b MOVE DISK 0 (from PEG C to PEG A inferred) A 30 B 2 C 1 STATE 05d = 0101b MOVE DISK 1 (from PEG C to PEG B inferred) A 30 B 21 C STATE 06d = 0110b MOVE DISK 0 (from PEG A to PEG B inferred) A 3 B 210 C STATE 07d = 0111b ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- axis of symmetry MOVE DISK 3 (from PEG A to PEG C inferred) A B 210 C 3 STATE 08d = 1000b MOVE DISK 0 (from PEG B to PEG C inferred) A B 21 C 30 STATE 09d = 1001b MOVE DISK 1 (from PEG B to PEG A inferred) A 1 B 2 C 30 STATE 10d = 1010b MOVE DISK 0 (from PEG C to PEG A inferred) A 10 B 2 C 3 STATE 11d = 1011b MOVE DISK 2 (from PEG B to PEG C inferred) A 10 B C 32 STATE 12d = 1100b MOVE DISK 0 (from PEG A to PEG B inferred) A 1 B 0 C 32 STATE 13d = 1101b MOVE DISK 1 (from PEG A to PEG C inferred) A B 0 C 321 STATE 14d = 1110b MOVE DISK 0 (from PEG B to PEG C inferred) A B C 3210 STATE 15d = 1111b notice the sweet symmetries around the axis indicated. PEG A mirrors PEG C. PEG A in STATE 00d is identical to PEG C in STATE 15d. PEG C in STATE 00d is identical to PEG A in STATE 15d. PEG A in STATE 01d is identical to PEG C in STATE 14d. PEG C in STATE 01d is identical to PEG A in STATE 14d. etc PEG B mirrors itself. PEG B in STATE 00d is identical to PEG B in STATE 15d. PEG B in STATE 01d is identical to PEG B in STATE 14d. etc
@alfonshomac
@alfonshomac 7 лет назад
you forgot to link to your patreon. I'm the new guy there btw [double handed- mid jump freeze frame high five]
@RaindropsBleeding
@RaindropsBleeding 3 года назад
Okay so I actually have a handheld binary counter and I just used it to solve tower of hanoi and it's even easier than you think. Because the toggles on my counter click, I listen for the clicks to tell me which disc to move. As long as I remember that disc 1 always moves to the right, it's impossible to mess up.
@RaindropsBleeding
@RaindropsBleeding 3 года назад
@3blue 1brown forgive me, but I can't make heads or tails of this
@machineintelligence5834
@machineintelligence5834 7 лет назад
Hi @3Blue1Brown I want to share a slightly different interpretation. The process of solving the Tower of Hanoi reminds me classical beginner's programming problem of swapping two variables content. You perfectly know that we need a third variable to swap the content of two of them, this is because we have the constrain that we can't send the information from one place to the other at the same time and without loosing one of the two (I call it quantum swapping :). That's exactly the analogous case in the Hanoi game "you can't put a bigger square on top of a smaller one" this constrain recast the game in a "swapping game", where the sticks works as variables. You are forced to use another stick and therefore follow the binary pattern. Can we apply the XOR trick by achieving a quantum swapping also in the Hanoi game? :) Thanks for your amazing work, a MS CS student.
@dravyachhajedshah9462
@dravyachhajedshah9462 3 года назад
Lol you can swap the values in python
@xynyde0
@xynyde0 2 года назад
yes, tower of hanoi is like copying a stack to a new place in memory with the order of sequence remaing intact all the time.
@benjaminv3748
@benjaminv3748 7 лет назад
Wow this is really cool. So technically you could solve the tower with n pieces just by following what the binary tells you. Given the time anyone could solve any! And eventually get quicker. Had a competition in my class before where we had to solve the 7 bit one as fast as possible, my record was 12(!) seconds! Using an app though, so 2 quick taps was enough to make 1 move. Then though I just got a feel for the moves requiered and memorized the pattern.
@bellac3993
@bellac3993 7 лет назад
I've never even taken a CS class but this is so fascinating! I love seeing videos appreciating the thrilling cohesiveness which seems to appear in every area of mathematics. Absolutely adore these videos, thanks for putting them out there!
@Kino-Imsureq
@Kino-Imsureq 7 лет назад
For all the people who are confused of the trick explained in the video, This is what it means... say i have 2 disks lets count in binary 01 -> move disk 0 to the nearest peg to the right. 10 -> move disk 1 to the nearest peg to the right. 11 -> move disk 0 to the nearest peg to the right. ok you get it now? heres the pattern remember to ignore when a digit turns to 0, but to not ignore when a digit turns to 1 so when i have 1s place, (disk 0) goes to the nearest peg to the right. dont worry about the size for this disk since its the smallest disk. when i have 2s place, (disk 1) goes to the nearest peg to the right UNLESS there is no smaller disk occupying the peg of choice. when i have 4s place, (disk 2) goes to the nearest peg to the right UNLESS, again, there is no smaller disk occupying the peg of choice. if you have a disk and its on the rightmost peg and you transfer it to the right just go to the leftmost peg and check if the peg is being occupied by a smaller disk. how about 4 disks. 01 - 11 -> use disk 2 formation 100 -> disk 2 goes to the nearest peg to the right. 101 - 111 -> repeat instructions i told you earlier :) 1000 -> disk 3 goes to the nearest peg to the right. 1000 - 1111 -> repeat instructions i told you earlier :) again order another smiley again :) so yeah if you master that you can become an absolute OP and solve a 20 ring tower of hanoi : ) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
@tiggerbiggo
@tiggerbiggo 6 лет назад
0:25 nah, you win in the category of "best educator" :)
@noway2831
@noway2831 6 лет назад
Very insightful.
@brownchocohuman6595
@brownchocohuman6595 4 года назад
Maybe the tower of Hanoi problem has 3 pegs to represent 0 bit, 1 bit and the carry bit P. S : this is just a random thought of mine. I haven't read or heard of it anywhere so it's most likely wrong 😅
@wojtekimbier
@wojtekimbier 7 лет назад
Please do check your volume levels to make sure they are between 50% and 100% of the possible range, if your video is so quiet people will have trouble hearing you on mobile phones, tablets, some laptops etc.
@Snuni93
@Snuni93 7 лет назад
Has anyone else noticed how the 3 of "Disk 3" looks an awful lot like a cartoonish mouth, especially when the eyes are shown
@nathanisbored
@nathanisbored 7 лет назад
The problem with "move it over once" is that the way I learned the rules of the puzzle is that you had to go from _leftmost_ peg to _rightmost_. So if you started with an odd number of rings, you would need to move it over twice (or once the opposite way). The way I always solved it was: odd numbered tower/subtower -> move next disc to destination you want the whole tower/subtower to be at even number -> move next disc to non-destination This pattern works throughout the whole puzzle, and I assume it's basically the same as the binary thing, but harder to keep track of. I used to obsessively do this puzzle with playing cards (i didnt have pegs and rings), and i went up to 13 one time (took 2-3 hours I think?). Every new card would take about twice as long, I guess because 2^n (oh hey, binary!!)
@kwarsha
@kwarsha 7 лет назад
If you picture the pegs in a circle instead of a line you could say that when the number of circles is even you do the first move clockwise and if it's odd you do it anti clockwise (or the opposite, depending on how you set up the circle). Basically the direction of the first move would be (-1)^n, where n is the number of discs (and then you decide which one between +1 and -1 is clockwise)
@vaitesh
@vaitesh 5 лет назад
@@kwarsha you can do that thing in a circle in opposite direction too. Like start the disc 0 to move in anti clockwise and disc 1 to clockwise. Will end up at the right solution. Circular things work in both directions. It seems In that case the kind of thumb rule (-1)^n will not work. Agree?
@bauagan
@bauagan 5 лет назад
If I didn't grow up with so called western world numbers, I'd find this video severely informative ;D I love this planet ;D
@msquarednet1
@msquarednet1 7 лет назад
I assume base-2 counting works for the Hanoi puzzle, because... of the THREE spindles, 2 of them are 'in play'. Is it true that FOUR spindle game would correlate to base-3 counting; and that an ELEVEN spindle game would correlate to base-10?
@macronencer
@macronencer 7 лет назад
This is one of your best videos! It really appeals to my sense of pattern :) One small note: I think the plurals of "two", "four" and "eight" are "twos", "fours" and "eights". No apostrophes are needed. Maybe this confusion arises because apostrophes are often used with digits to reduce ambiguity, e.g. "10's", "100's"; this isn't the case for numbers spelt as words.
@fossilfighters101
@fossilfighters101 7 лет назад
+
@trueriver1950
@trueriver1950 3 года назад
Either is correct here but they carry different nuances. Pedantry alert! Twos is the plural of two, so that there are three twos in six, as you correctly say. But two's indicates ownership or belonging. Think of when we say my girlfriend's implying my girlfriend's place. (Note that's different from my girlfriends which would suggest polyamory). So the two's implies the place where the twos are listed, the eight's the place where the eights live, and so on.
@macronencer
@macronencer 3 года назад
@@trueriver1950 You are logically quite correct but - forgive me - idiomatically wrong. Just because you can imagine using "two's" to stand in for "two's place" doesn't mean that it's common usage. As far as I know, the construction you describe applies to people's homes, but not digit positions. Of course, it could be that everyone's been doing it like that for decades and I simply hadn't realised... in which case, my apologies. True story: my dad was a primary school teacher a long time ago, and sometimes one of his pupils would say something like "I'm going up my Nan's." His reply was usually something like "would you like to borrow a ladder?" He was such a joker!
@wiregold8930
@wiregold8930 2 года назад
... numbers spelled as words ... "spelt" is a grain.
@macronencer
@macronencer 2 года назад
@@wiregold8930 It's a perfectly correct British spelling.
@myrus5722
@myrus5722 6 лет назад
I didn’t find the Hanoi puzzle very challenging because most of the time there is only 1 possible move that isn’t retracing your steps. In some situations where there are two moves that don’t retrace steps (the most their can be) it is still easy to see which move will get you toward your goal, as long as you ask yourself the question “ will this accomplish my goal?”.
@TheForsch3r
@TheForsch3r 6 лет назад
There are only 2 possible moves for the configurations where all rings sit on one tower, and 3 possible moves for every other configuration. If you assume that we are always starting or finishing with all rings on one tower, its safe to say that there are always two unique, non retrogressive moves. Therefore every state you arrive upon has an choice, and since there is only one fastest method, every state you arrive upon has a right and wrong answer.
@cameronadams4366
@cameronadams4366 7 лет назад
you should make your "intro eye" blink ... after it has done the (beautiful) "pupil shrinking" animation... ;)
@rarebeeph1783
@rarebeeph1783 7 лет назад
When you realize this result in 8th grade, only to find out the exact same thing on youtube, years later ;-;
@chmagiccharles
@chmagiccharles 7 лет назад
Hey 3Blue1Brown, what do you use for the music in your videos? It's really calming and focusing and would be great for listening to while studying
@esyrim
@esyrim 6 лет назад
I discovered Towers of Hanoi early on, as a side/minigame in Escape from Paradise. I was pretty young so it was a bit difficult. At the least I could get to level 2 (only 4 discs haha)
@johnchessant3012
@johnchessant3012 3 года назад
Who's here again after Mathologer's video!
@trueriver1950
@trueriver1950 3 года назад
Yep!
@MrSilbarita
@MrSilbarita 7 лет назад
Holy! This is absolutely amazing. I solved this puzzle for/with a student of mine and came to these conclusions, but the binary counting perspective is simply mesmerizing. Thank you for this video!
@jfp0763
@jfp0763 2 года назад
This would help 2 months ago when I solved a 9 disk tower of Hanoi... Man that shit was hard i kept forgetting what i was doing
@wyattstevens8574
@wyattstevens8574 Год назад
In a Numberphile video about this, I learned that disks with like parity are never consecutive on the same peg.
@mapnzap
@mapnzap 7 лет назад
well done. I like to think of periodic boundaries where even number disks go one way and odds go the other.
@swagatochatterjee7104
@swagatochatterjee7104 5 лет назад
Isn't it very obvious that solution to time complexity of Towers of Hanoi, that is it's recurrence relation, is 2^n -1 , the maximum number you can make by n binary digits. And you can reach this maximum number, by adding 1 to this number starting from 0. I don't understand why is this an astonishing discovery.
@dAvrilthebear
@dAvrilthebear 2 года назад
11:10 - that's wrong! All the disks end up on the central peg, when they should end up on the right peg. Why?
@MrVbarroso
@MrVbarroso 5 лет назад
Once you see disk 3 sending you a kiss, you cannot unsee it
@CarelessMiss
@CarelessMiss 6 лет назад
7:53 where did it come from why does it work where did it come from binary code joe
@AssistantCoreAQI
@AssistantCoreAQI 5 лет назад
No.
@drabadraba101
@drabadraba101 5 лет назад
Woooaaahhh fine structure constant easter egg
@jony7779
@jony7779 7 лет назад
Keith Schwarz! Did you study CS at stanford?
@trueriver1950
@trueriver1950 5 лет назад
This is overly complicated if the aim is to solve Hanoi. The shortest algorithm is as follows 1. First move: only legal moves involve moving the smallest. If there's an odd number of disks move the smallest to the destination; if even move smallest to the other peg. Note which direction it moved. 2. On even numbered moves make the only move available move that leaves the smallest where it was 3. On odd moves move the smallest in the same direction as step 1. That's it! You do not need the rest of the binary number, just the last digit. In effect you only need odd-even so a simple toggle is enough, adding in modulo 2. And when adding mod 2, the numbers look the same in any base: 1 0 1 0 ... Binary is a distraction: it's mod 2 that matters
@trueriver1950
@trueriver1950 3 года назад
Hey its me again: just read my comment from two years ago and looked to see who posted it LOL
@thespaceman88p79
@thespaceman88p79 5 лет назад
you've done a little error at 5:59 11111111 in binary equals to 256 not 255 (which is 11111110 in binary) cause 2**8 = 256 otherwise realy nice video keep going like this (sorry for grammar error )
@happygimp0
@happygimp0 4 года назад
Sorry but you are wrong. . 1_2 = 1_10 . 10_2 = 2_10 . 100_2 = 4_10 . ... = ... . 1'0000'0000_2 = 256_10 . 1111'1111_2 = 2_10**0_10 + 2_10**1_10 + 2_10**2_10 ... 2_10**7_10 = 255_10 . (you may have to copy this to a text editor to see it better) . . Because for every 2_10*x, you add a 0_2 at the end of the binary representation of x: . 2_10 * 1_10 = 10_2 * 1_2 = 10_2 . 2_10 * 2_10 = 10_2 * 10_2 = 100_2 . So 1'0000'0000_2 = 2_10*2_10*2_10*2_10*2_10*2_10*2_10*2_10 = 2_10**8_10 = 256_10 . 1111'1111_2 = 2_10**8_10-1_10 = 255_10 n_10 are decimal numbers, n_2 are binary numbers
@Liggliluff
@Liggliluff 4 года назад
The binary method shown in this video work great for odd numbers of discs, as the result ends up on C. But for even number of discs, it will end up on B. I thought the goal was to end up on C. But fear not, all you have to do is to move the first (0) disc to the left and not right, when you have an even number. That's all.
@МАҐВРЄМЄНІ
@МАҐВРЄМЄНІ 7 лет назад
I really loved math when i was studying it at school and you give me so much unsuspected insight into topics i thought i knew very well. Thank you so much. After each of your videos i feel that i learned something new.
@Smurph-20
@Smurph-20 7 лет назад
Every number system, when represented in its own base, is "base 10"
@frechjo
@frechjo 7 лет назад
This HAS to be related somehow to the Chinese Rings Puzzle somehow... Please get your friend to tackle it and make a video about it, I'm scared to think about it on my own! :P (Seriously, I wouldn't know where to begin at)
@frechjo
@frechjo 7 лет назад
Nah, I took a look at it. Turns out it's pretty boring. At each step you only have too choices, and one of them takes you back, so it's just a linear path connecting all possible configurations. And now I remember why I cut my 12 rings puzzle into 2 with 6 rings! :/ At least I found that, if we encode rings entangled as ones, and the rings disentangled as zeros, the complete path is the sequence of natural numbers represented in Gray code, form 0 to (2^number of rings-1) ( en.wikipedia.org/wiki/Gray_code )
@victor-cd3ww
@victor-cd3ww 7 лет назад
Marvelous again. When I was younger, my grandpa taught me a slightly different version: A larger disk not only cannot stop over a smaller one, but it cannot pass over it at all. This essentially makes the game longer, which I suspect was the goal of my grandpa. I kind of remember talking about it with a friend a couple years ago, and I think we came to the conclusion it was very much like classic Hanoi, but with base 3 instead of base 2. Maybe I should take out a pencil and check that again.. EDIT: Shame on me, I should have binged the series like a true 3Blue1Brown fan before posting this.. Keep up the good work!
@roterfrosch5808
@roterfrosch5808 4 месяца назад
You move the first disk 1 place. The second: 2 places. The third: 4 places, The forth: 8 places....
@aquawoelfly
@aquawoelfly 7 лет назад
4:20 forget resisting the urge to see it as ten... i have to reiast the urge to tell a "there are 10 types of people in the world... so there are 11 types of people those that understand binary, those that dont, and those who realized this joke was originally in base 3.
@davidwuhrer6704
@davidwuhrer6704 7 лет назад
In base 3 it would be 10.
@aquawoelfly
@aquawoelfly 7 лет назад
Was ORIGINALLY which is why in base 2 it becomes 11
@therealDannyVasquez
@therealDannyVasquez 7 лет назад
Jokes that need an explanation. Hilarious!
@davidwuhrer6704
@davidwuhrer6704 7 лет назад
amanda cabrera Ok, got it. I still think it is funnier with 10. Playing with expectations. Anyway, I put it in my fortune cookie file. I hope you don't mind.
@pietervannes4476
@pietervannes4476 5 лет назад
@@davidwuhrer6704 yeah but with 10 its got old. Even in tertiary. I prefer this one
@earlsworkshop
@earlsworkshop 7 лет назад
Oh the memories! The very first program I wrote for my Assembly Language class project was the solution for the Hanoi puzzle on a Dec PDP11-45 back in 1975.
@bibanez135
@bibanez135 5 лет назад
When I started doing python I made a script to solve the Hanoi towers, but I didn't know what recursion was so I analyzed different cases and found a really weird relationship between numbers and letters. I thought about recursivity as you mention it here, but I solved it completely different for n disks with the most efficient moves. I could show you the code, but it is very messy and I, to this day, still not understand how the math I did really works xDD
@dipu6174-t8n
@dipu6174-t8n 7 лет назад
Love all your videos. Easy to follow the lectures and the graphics surely make an awesome impact on understanding. Thanks :)
@endertrot9998
@endertrot9998 7 лет назад
As someone who's in the middle of a computer networking course, I really like the way you explained binary. While I already know how it works (thanks IPv4!), your explanation is really good, and if I have to ever explain binary to someone else I'll probably have to borrow from this.
@NonTwinBrothers
@NonTwinBrothers 7 лет назад
I've learned the relationship between the ABACABA pattern and the Tower of Hanoi from Pocket83's channel.
@DrGerbils
@DrGerbils 7 лет назад
And he probably learned it from Martin Gardner's 959 book "Mathematical Puzzles and Diversions."
@xavierpaquin
@xavierpaquin 7 лет назад
Are there variations of the puzzle whose solutions relate to counting in other bases?
@TheFinagle
@TheFinagle 3 года назад
4:13 I read binary :'zero' , 'one', 'ten', 'eleven', ' one hundred', ... Call me a monster if you must but 10 is still 10 to me even if its not a base ten series. (And yes I keep track of it being in alternate bases)
@seriousmax
@seriousmax 7 лет назад
Found the puzzle online: www.mathsisfun.com/games/towerofhanoi.html
@419
@419 2 года назад
I wrote my own algorithm to solve this without any resources and came up with a similar system, but instead of binary I just say "up" or "down". Basically if you have an even amount of disks, move the first disk only up, the second down, third up, etc. And if you have an odd number of disks only move the first down, second up, third down, etc etc. Then it's just as simple as remembering which disk moves up and which moves down. Here's the messy pseudocode I came up with, and while it's a mess I haven't seen anything else that does it quite this way // For 5 disks, a is the smallest, e is the largest, and the positions they move to in order a3 b2 a2 c3 a1 b3 a3 d2 a2 b1 a1 c2 a3 b2 a2 e3 a1 b3 a3 c1 a2 b1 a1 d3 a3 b2 a2 c3 a1 b3 a3 a_moves_when=1 3 5 7 9 11 15 17 19 21 23 25 27 29 31 b_moves_when=2 6 10 14 18 22 26 30 c_moves_when=4 12 20 28 d_moves_when=8 24 e_moves_when=16 ring_count=5 a_total_moves = 2^ring_count-1 b_total_moves = 2^ring_count-2 c_total_moves = 2^ring_count-3 d_total_moves = 2^ring_count-4 e_total_moves = 2^ring_count-5 a_pos=1 b_pos=2 c_pos=4 d_pos=8 e_pos=16 while(a_pos
@MrDuke1998
@MrDuke1998 7 лет назад
When will you be uploading the essence of calculus series??
@justsomeperson1282
@justsomeperson1282 6 лет назад
Towers of Hanoi is also related to the partial sum of 2^n...
@justsomeperson1282
@justsomeperson1282 6 лет назад
That is, it has exactly (2^(n-1))-1 moves, where n is the highest-numbered disc.
@Ikkyblobia
@Ikkyblobia 7 лет назад
I actually remember when I first noticed this. I didn't really understand it in such a formalized way, though.
@Lopoi
@Lopoi 7 лет назад
Ohh, This reminded me of 2 years ago, there was a competition to see who could solve the tower the fastest in my uni. I didnt join, but I did end up making up a solution to the puzzle, which I can't remember well, but it goes along like this: Always mov the smalles number that wasnt moved in the previous round; Never place odd numbers on top of odd numbers, or even numbers on top of odd numbers; Well, thats all I can remember for now, I will see if I can find my papers that I drew on. Now back to the video.
@FengXingFengXing
@FengXingFengXing Месяц назад
Tháp Của Hà Nội
@CristalMediumBlue
@CristalMediumBlue Год назад
8:45 peg 3 looks like it is doing the duck face or sending a kiss
@geodave227
@geodave227 3 года назад
I figured out as a kid that if you have an ODD number of disks, the first step is to move disk 0 to the target peg, and if you have an EVEN number of disks, the first step is to move disk 0 to the non-target peg. So in some sense it was a parity solution. And then I pretty much solved it recursively. Interesting tie-in to binary counting, however.
@Piffsnow
@Piffsnow 7 лет назад
Wow. This is already awesome ! And now : let's check part 2. :)
@HikaruAikawa
@HikaruAikawa 7 лет назад
Looks a little bit weird how, around 7:25 for example, the piece for 0 is the darkest and the piece for 5 is the lightest, while in the number below the bit corresponding to 0 is the lightest and 5 is the darkest. Other than that, really cool video! We learned about the recursive solving of the Hanoi towers problem in class but I never made the connection to binary.
@RizkyMaulanaNugraha
@RizkyMaulanaNugraha 5 лет назад
Binary works because the algorithm reduce to binary complexity for each actions. This is useful when you measure it's complexity. For each depth of recursion, we essentially do 1 + 2*(steps for that depths). To ilustrate, let f(N) be the number of steps needed to move the pegs efficiently. It is a recursive function. For f(N) the steps involves: 1. Moving the rest of the pegs (N-1) means f(N-1) steps 2. Moving the bottom peg count as a step 3. Moving the rest of the pegs again, means f(N-1) steps. algo 1 and 3 is the same, so it is the same steps. So: f(N)=2*f(N-1) + 1 The recursion ends when f(1) = 1 (one step to move one peg). One now can easily reduce the counts by finitely recurse until f(1), which is, if we write it as sum of power of two, is the same as writing binary in this form: f(N) = 2^N - 1 --> which is basically all 1 in binary until N digits. So, for 2 pegs, it is like: 11 in binary (2 digit). 3 pegs becomes: 111 in binary (3 digits). and so on. It's just because: 2^3+2^2+2^1+1 is equivalent to 1111 in binary for 4 pegs. Amazing.
@Bluedragon2513
@Bluedragon2513 5 лет назад
*realizes I could solve tower of Hanoi when I was younger and realizes I might not be a genius*
@SunnyKimDev
@SunnyKimDev 5 лет назад
5:46 this is when i got what 3b1b was saying: i made a cpde that prints out the stepbystep solving of hanoi that prints out A C A B C B ... where A C means move the top one in A to C. i used recalling?(재귀) functions for it: hanoi repeats itself. for blocks in A, move all but the last one to B, move the last one to C, move everything in B to C. how do i move everything except the alst from A to B and B to C? recall that function. all that the function does is move blocks from one place to another. why did i get hanoi=bi in 5:46 ? 1.move all-1 from A to B 2.move one to C 3.move all to C(which is the same as step 1) 1.increment all-1 so all digits are 1 2.add 1 3.increment again(which is the same as step 1) a programmer's explanation on why this work. 3b1b you and your friend is a genius!
@SunnyKimDev
@SunnyKimDev 5 лет назад
ah, 재귀 is recursive and not recalling. sorry... as a programmer, i work with recursive functions a lot, so i am used to these kinds of situations, but maybe i was hoping a mathematic approach?
@SunnyKimDev
@SunnyKimDev 5 лет назад
9:55 thats python with 2 functions, maybe i can use 1 function, but i used 3 variables passed down. function ha(var s,var e,var b) s is for start, e is for end, b is for bystander. the original question is to get everything from peg A to C, so ha('A','C','B'); and it would call ha('A','B','C); console.log("A C "); ha('B','C','A');
@trueriver1950
@trueriver1950 3 года назад
4:22 there are ten sorts of ppl in the world. Those who can count in binary And those who can't
@laurinneff4304
@laurinneff4304 5 лет назад
There are 111 types of people: those who understand binary, those who don't understand binary, and those who didn't expect a unary joke here
@goffe2282
@goffe2282 7 лет назад
Hi. First of all, I love your videos, but I don't see how binary counting solves the towers of hanoi with the algorithm you have given simply because it does not guarantee that the tower moves from peg A to peg C. It seems to me that this will only happen when the tower is of even height, the resulting stack will otherwise end up in the middle, and you need to compensate for that somehow. Am I missing something? The thing is that if you have to take care of this then the binary counting solution is not as clean and elegant as we might originally think. It's still pretty though, and I hadn't seen it before. Personally, my favourite recursive algorithm for solving the towers of hanoi (which I am in no way taking credit for, but it is also optimal and moves any size tower to the right peg) is the following, where 'hanoi n to from via' will solve the towers of hanoi by moving 'n' discs from peg 'from' to peg 'to' via peg 'via'. The results is a list of pairs [(A, C), (C, B), (A, B), ...] where every pair (A, B) means move the top disk of A to B. hanoi n from to via = if n = 0 then [] else (hanoi (n - 1) from via to)@ (from, to):: (hanoi (n - 1) via to from) here [] is the empty list, @ is list join, and :: is list addition. If you call 'hanoi 3 A B C', for instance' you will get the result [(A, C), (A, B), (C, B), (A, C), (B, A), (B, C), (A, C)] moving a tower of size 3 from peg A to peg C whereas your algorithm, if I read it correct, would move the tower from peg A to peg B. As you noted, these algorithms get really tiny and are great for explaining recursion. We don't care how the smaller problem is solved, we just assume that it is and work from there ;). I just found your channel (thanks to Ask a Game Dev) and I'm looking forward to seeing your other work. I love seeing math made accessible.
Далее
Binary, Hanoi, and Sierpinski, part 2
13:40
Просмотров 299 тыс.
Fractals are typically not self-similar
21:36
Просмотров 4 млн
МАЛОЙ ГАИШНИК
00:35
Просмотров 402 тыс.
I Built a SECRET Lamborghini Dealership!
33:02
Просмотров 4 млн
Лучше одной, чем с такими
00:54
Просмотров 758 тыс.
Why do calculators get this wrong? (We don't know!)
12:19
How to lie using visual proofs
18:49
Просмотров 3,3 млн
How Binary Works, and the Power of Abstraction
15:17
Просмотров 303 тыс.
I Made A Water Computer And It Actually Works
16:30
The Sierpinski-Mazurkiewicz Paradox (is really weird)
13:03
Solving Wordle using information theory
30:38
Просмотров 10 млн
Researchers thought this was a bug (Borwein integrals)
17:26