字幕列表 影片播放 列印英文字幕 So I bought a new drawing tablets because I've been falling all these instagram artists, and I thought it would make me a better drawer. Well, apparently didn't. Unfortunately, it's too late to return it, so I might as well just use it to teach interview questions, which is why I'm here. So what are my favorite interview questions? I'm kind of curious if you can solve it. So ready. Okay, you have a function called random that generates a number from 0 to 1 randomly, and it's uniformly distributed. Now calculate the number pi. Now I really like this question because it it sounds so absurd in the beginning, right? It's almost as if as it's almost order to this question. Zoe has four apples. Zoe gives one apple to Tom, and then she gives two apples to Gary. Now calculate the mass of the sun Anyways, you can try to solve it, but ah, let's go to the drawing board. Oh, shit. Sorry. I think that's the wrong window. Um, it's really nice looking Patrick, though I wonder who drew it. So the basic idea is to randomly draw points from a 1 to 1 square or like a 1 to 1 grid, since you can call the random function twice. And then what happens is that you get to numbers and then you use them one for the X axis and one for the Y axis. So, for example, if X becomes their 10.2 and why it becomes their 0.6, then where you gonna get is like maybe a point somewhere like here, right? So why don't we draw a few more of these? Debatable. Now I'm gonna give you a hint. So I'm gonna draw something, and I think you will know how to do it now. So as you can see, the goal here is to count all the points in the circle and count all the points in the square. The ratio between these two numbers will be pretty close to the ratio between the total area of this circle and the Torah area of this square. So how do you know if the point is in the circle or not? Well, it's pretty simple. You just take the distance between the point to the origin and if it's smaller than one, then it's in the circle. For example, let's take this one. All right, you know. So that line, what is the distance? Will the distance. It's basically X squared, plus y squared square root of that right. And then, if that is smaller than one, then it's in the circle. If it's bigger than one, then it's outside the circle, but still inside the square. And then Alan, just basic algebra. Right? So we all know that the area of a circle is pi r squared. Oh, you didn't know? Fucking idiot. And then, in this case, the area of a square would be two times are, and then you square that, and then with this ratio is going to be the same as the ratio of the number of points in the circle. So numb point circle, divided by the number of toto points. So, Toto So then now we want to do is we just wanna isolate pie. So that's pretty easy, because we know that our equals one here so this can be gone. This becomes 22222 becomes four. And then we just put the four to the other side. So now it becomes pie. You close four times the number of points in the circle, divided by the number of points, Toto, Right? I don't want to write it. So I'm just gonna draw these booby looking things. This is called a coded. So that's nice. And then, if you want a good example, so we could actually count them. Okay. How many points do you have? What you have? Ah, I don't know. Maybe 88 points here and that. How many points do we have, total? Like maybe two more points here. Obviously, I'm not counting, but let's just say it's eight. Divide by 10. So we get a divide by 10 times, for I guess that's pie, right? And then, yeah, so that's pretty much it. Ah, yeah. Quoting it should be pretty easy, so I'm not gonna go over it. Actually, actually, actually, I changed my mind. Um, I think I am going to show you the code for it. And, uh, yeah, because I feel like I can explain it a little bit better while cooling. So let's do that. All right. Cool. So we got her online ripple right now, and yeah, let's just start quoting it. So what we want to do is call it estimate pie, and then I'm going to give it an end meeting. How many points do actually want to put in? So the more points, the more accurate. Right? Okay, cool. So then, first I want to know how many points are in the circle will initialize to that to zero and then also how many points or end to Toto meeting in the square. So then next, where we have to do is just keep looping and keep adding these points. So this means we're just looping end times. Ah, Okay. Let's see. Is it is it? This is it, right? No, that's not it. Ready, huh? Okay. Let me check something. Okay. Excellent. Okay. Ah, pi ce on random. Okay, cool. Random uniform. God got it. All right. So first I wanna give my ex a number uniform from 0 to 1. Same thing with my why 01 And then we want to calculate the distance of the distance with X squared. Plus, why squared and then yet we're just gonna keep it at that. We don't need to square root, because what we care about if this since it's smaller than one. So if you square root Something that smaller, That one's gonna be smaller than one. If you square with something that's bigger than one, it's gonna be bigger than one. So who cares? All right, call. So then, if it is inside, like if it's smaller Dan one, then that means it's inside circle. So we add one. And then, no matter what, we're just gonna attitude point to the total. I got it. And in Indiana, I think that's pretty much it. Remember when we did our algebra? We did the formula. We saw what pie was. So there you go. You just returned pie. And in pie, we remember that it's four times the number of points in the circle divided by the number of points in Toto. Okay, let's try this out, Excellence. All right. Um, estimate pie. Imagine if I just want 10 points in there. Ah, God damn it. All right, Random. Okay, let's try this again. Estimate pie. Excellent. So 3.6 pretty close. I guess the more points we put into our graph, the more accurate it becomes. That is not more accurate. Okay, maybe 1000. Okay, there we go. 3.17 pies actually, 3.14 so Okay. Okay. Yeah, A little bit more accurate than let me check with pie is actually 3.1415 Okay, 100,000. Okay, getting closer. 3.14 And remember, this is random. So each time you press it or start each time you call it, it's gonna give you something different. So, uh huh. Okay, Yes. Oh, let's try another one. Let's just add another zero. Okay. Cool. Yeah, Almost 3.1415 It's probably not gonna get that accurate. That just added one more zero. I mean, it's not my computer anyway, so I'm not paying for the compute cost. It is quite long. Okay. Oh, wow. 3.1415 Actually, that's pretty accurate. Yes. Oh, there you go. That's what. Ah, that's what it is. And that's how you do it. So Yep. All right. Cool. And ah, I hope that was helpful. And back to the video. Uh, quoting it should be pretty easy, so I'm not gonna go over it. I've attaching the description if you want. No, but yeah, I feel like these tutorials check out quarter pro and also check out my new educational channel, Joma Academia. That's pretty much it.
B1 中級 你能解決我最喜歡的面試題嗎?(數學+CS) (Can you solve my favorite interview question? (math + cs)) 8 0 林宜悉 發佈於 2021 年 01 月 14 日 更多分享 分享 收藏 回報 影片單字