Placeholder Image

字幕列表 影片播放

  • So today I'm goingto talk about Ryker version, and I know computer file has done records and before, but this time we have, ah, bit off a different look.

  • So one thing this we're going to use Python people a bit.

  • Ski hat itself like a scary word, but it's actually I don't think it's so difficult.

  • And I think the best way to explain it is to look at the problem, which is, actually, I think, quite hard to solve without workers, not hot.

  • But once you know Rikers in, it becomes quite easy.

  • Sell off like it's a magic trick and programming.

  • It's like a magic spell.

  • And once once you know it, you can solve things you couldn't solve before.

  • It's like a superpower, So I want to.

  • I want to give you a super problem.

  • New superpower.

  • The problem is, is quite famous.

  • It's the towers off annoy, and it's a little puzzle.

  • So you have some some disks here.

  • Uh, remove this and there are three places you can put the disks, and the goal is to move all the disks from here from a to C, and each time you can only move one off the discs like this.

  • And the other hole is you can always only put a smaller just on the bigger this tree cannot put this year.

  • But here, you know, you could puts us here or here, and so is the problem Is to move all of this from from there to there.

  • Let's look a bit off A simple A case, which three risks.

  • So how do I do this?

  • Mm.

  • I moved to this year.

  • So the wolf, this one here, this fun back.

  • So I know that take, huh?

  • This one here half and head over.

  • Okay, but how do we solve this problem in general?

  • I mean, how do we know we had to move the better moves to this foot?

  • Somebody was four or five and so on.

  • And actually, I want to program a computer to move about a garm toe.

  • Do this, but I'm self leaving out of a body armor for today.

  • And it was another time.

  • It's left, doesn't exercise, and I just print the move.

  • So, like, move funds from a to B movie, this form A to see and we have tend to play the oboe ourselves.

  • Okay, Okay, so I'm going to use Typhon.

  • I'm using something called Jupiter, which I'm also using them a lecture.

  • It's a very to fight hyphen programs interactively.

  • Is that some things people could use?

  • Or is it something you have to subscribe to know you can dollar that?

  • Actually you don't know something called Anaconda, so you don't big Snakes Anaconda, which has a little snakes like Priceline.

  • It's and particular Jupiter, which also has something to this pipe.

  • Nothing is also planet.

  • I've been told something like this.

  • So let's first of all, do some simple pricing.

  • I just want to define the function move, which gets two kilometers F or form and T for true.

  • And then I want to put on my robe out.

  • Unless I say I'm just going to fix us as a splint.

  • Move disk from somewhere to somewhere on dhe exclamation mark.

  • It's an order, and I say former F committees, There's a little bit off if you're using here and let's test it, let's see, Move a C.

  • And he has moved us from a to see.

  • Okay, so let me say a little bit more about functions.

  • Let's say we want to implant.

  • Implement another function, which moves a disk from one place to another via 1/3 place.

  • There's just an example.

  • So how would I implement is I could just talk to Quinn statements, but really more clever way is that I used the function move I've already written.

  • Okay, so I did find a new function called Move Lawyer.

  • Let's get three perimeter an F or form a V for via and the tea for two.

  • Okay, And now, instead of doing my client's statement or my robotic arm moves, I call the function for defiance.

  • I say move from to via and then move Well, yeah, come to okay, Tested again via a bi bi to see Okay.

  • And it does the job, though.

  • The point here is that we define one function and calls and other functions of function like source of the task, and it uses other function to accomplish at school.

  • And here the function move.

  • I, uh, calls the function move and actually move itself called splint and so on.

  • So here's a question.

  • Does it ever make sense off a function to call itself?

  • It's according another function to call itself.

  • Let's just make a silly example.

  • Others function.

  • If you don't know a good name for a functioning, we call it food.

  • That's what was a good name for a function.

  • And if you don't know a good name for cannon meter, you call it X and full of ex calls for vex.

  • Okay, so what happens now?

  • If I say full off?

  • Three.

  • What's going to happen?

  • I have no idea.

  • It's just gonna get stuck, isn't it?

  • It's gonna go 33333 or something like this.

  • No.

  • Oh, there's a star.

  • Oh, for Violet was running happily.

  • And then it reports an elderly incursion ever maximum Rikers in depth exceeded.

  • So what happened is the function August calls that save close itself.

  • Course, it says, and then use up what's called a stack.

  • At some point, the steak is full and the support in question that's not a very impressive use off incursion.

  • That's about depressing.

  • Nothing, nothing useful is happening.

  • So let's look hot.

  • Bacon usually Kirsten to sources Hanoi problem.

  • Here's the idea.

  • Okay, let's say you want to solve the Hanoi problem for four discs.

  • More photos from a to see using B it's an intermediate place.

  • So now if we would know how to sauce the problem for three disks, then we would be fine.

  • Why?

  • Because first, I moved three discs from A to B, this time using C.

  • It's an auxiliary place, so let's just do this.

  • And then I move on disk from a to see that that can always too hard.

  • And now I moved three disks from B to C using a.

  • It's an Oxy, really, and I'm done simplified.

  • It's a problem for four disc to solving the problem for three disks.

  • And now it's not much imagination to see that there was nothing special on having four discs that works for any number off this for any number off this.

  • If I want to solve it, it's enough.

  • If I couldn't solve it with one disc lis and this, we can just lie down as a person put home okay?

  • And so I'm defining a function called Hanoi, which has four perimeters as a number off this and then the name off the form position the name off the paper position and the name off the two off the target.

  • Okay, now, what was the idea.

  • First of all, I want to solve the problem for n miners.

  • One this move and Milos wonders from form to via and this time using my target My tea as a serial depositions, I say Hannah Lee and mine was one.

  • I move form form via two to age with help.

  • Okay?

  • And now I'm just moving one disc from a two season.

  • I'm using my move function from from True.

  • And finally I move and miners wonders which I know at help Opposition tools A to position using form this time a sock serial.

  • Here's a helper.

  • So Hanoi So we're moving for must have a position using the prone position to the two position and I only to say if youse n minus one disks so after the last move here.

  • So it's turned out.

  • You see Hanoi for a while, I'll be to see and what's going to happen.

  • Oh, it's a transformer And forget it, because now Mmm.

  • Did I get stuck with a 333 things like food.

  • Was it normal that each time it reduces the number off this, I have no way to start No.

  • Yet went on to negative In the end, it was moving large amount of negative disks alone.

  • That's not that doesn't work, because each times was actually not better as who.

  • Each time we call ourselves, we never stop.

  • So we need a bass case.

  • We need an easy case.

  • So question is voters the easy case for Hanoi?

  • What one wonders.

  • It seems to be easy, because wonders, we just have to move from A to C.

  • But it's even easier.

  • Case.

  • No disk.

  • Exactly.

  • What do we do when we have conversed?

  • Noticed?

  • Nothing?

  • Nothing?

  • Exactly.

  • Yeah, okay.

  • And the nice thing is, then the problem for for for for one disc is can be reduced to the problem is noticed because we move no discs from a to B.

  • We do nothing.

  • You move those wonders for me to see and then remove notice from B to C.

  • So it's the same, but way haven't even worked with your base case.

  • So that's let's do this year.

  • So we have to check if n zero.

  • Then we do nothing.

  • Pause passes performed for do nothing.

  • Always we do what I say.

  • Otherwise we we need to reduce the problem.

  • I know I'm using the top you see Now let's see what happens and we get a recipe.

  • So it's just trying to see where that's correct.

  • I'm the vote.

  • Yeah.

  • Move unders from a to B.

  • Move wonders from a to C move Unders from B to C.

  • Okay, well funded from a to B, well funded from C to A.

  • So what should like a delighted wonders Come see to be who funds us from a to B who wonders from a to C move under B to c move on this from B to A.

  • I'm not a very good one, but move under from sea to a Okay, Very good wonders from B to C.

  • It's getting exciting wonders from a to B.

  • Okay, now we feel any wonders from A to C and way when this would be to see program seems to work.

  • So using records in it's not very hard to source is public.

  • But without the incursion I've been stuck in, you have to think about like, oh, maybe have to divide it by three year by two.

  • I don't know that some clever way, but why do we need to be clever so wasting our brain power.

  • It's This is magic trick of Rikers in which helps that solving this problem much easier there again, those of you familiar with any of the sea like languages, you know, Java C plus plus whatever.

  • I find this very familiar.

  • The incoming parameter arguments.

  • Sometimes gold is labeled and the name of the function is factorial.

So today I'm goingto talk about Ryker version, and I know computer file has done records and before, but this time we have, ah, bit off a different look.

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

A2 初級

遞歸的 "超能力"(Python中) - Computerphile (Recursion 'Super Power' (in Python) - Computerphile)

  • 2 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字