Can you solve my favorite interview question? (math + cs)

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ม.ค. 2020
  • HOW DO I GET A TECH JOB?
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
    📚 Video courses from JomaClass:
    🎓 New to programming? Learn Python here: bit.ly/joma_python
    🎓 Learn SQL for data science and data analytics: bit.ly/joma_sql
    🎓 Data Structures and Algorithms: bit.ly/joma_dsa
    💼 Resume Template and Cover letter I used for applying to software internships and full-time jobs:
    resume.joma.io
    💼 Interviewing for jobs now? Get access to interview question database, courses, coaching, and peer community today:
    www.tryexponent.com/?ref=joma
    📱 SOCIAL MEDIA
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
    / jomakaze
    / jomakaze
    / jomakaze
    Some of the links in this description are affiliate links that I get a kickback from

ความคิดเห็น • 2.1K

  • @jomakaze
    @jomakaze  4 ปีที่แล้ว +244

    Check out my second channel: th-cam.com/channels/WhwybsQg-EeBJpsqtmbscw.html for snackable educational content

    • @Ultrajamz
      @Ultrajamz 4 ปีที่แล้ว +2

      Joma Tech what laptop or screen are you using to draw? Ipad? What might you recommend to do the same thing using linux/windows machines?

    • @PedroAugusto0
      @PedroAugusto0 4 ปีที่แล้ว +2

      God damn, man I found your channel today, I loved it the way that you put some funny things in videos, congrats! I thxs 4 this tip

    • @daxi-yw8ui
      @daxi-yw8ui 4 ปีที่แล้ว +1

      Hey bro calm down that's called Montecarlo and it's a procedure literally everybody knows and my computer science teacher gave me this shit First day of second year High school

    • @freemind.d2714
      @freemind.d2714 4 ปีที่แล้ว

      There have onther way to do so, and generate one point only use the random function once : )
      1: Take 1 as fixed radius, Hand choose a circle angle N ( any angle value with in (0, 180] )
      Loop: (Reapet 2~3, get as many point as possible)
      2: Use uniformly distributed random function generate number 0~1 and multiply it by N as random angle
      3: Draw the point on polar coordinate system, format: (radius, angle)
      4: Calculate the distance between two adjacent points and add them up to approximate Arc length ("adjacent " can be done easily by ordering the x, y value of coordinate)
      5: Because: Arc length = N/180·πr, and r = 1; so: π ≈ approximate Arc length * 180 / N
      More point we have, the smaller N we use, better the approximation we get, as this kind of prerequisite the only thing we can do is approximation.

    • @tisonludovic6858
      @tisonludovic6858 3 ปีที่แล้ว

      num_point_total will be n 😉. You should try with 3 or more dimensions. Monte Carlo is made for bigger dimensions.

  • @Waiel
    @Waiel 3 ปีที่แล้ว +2084

    My favorite interview question is
    *“What’s your name?”*

  • @joeface448
    @joeface448 3 ปีที่แล้ว +1787

    "Fuckin' idiot..." made me almost cry from laughing so hard. You bastard, gotta call me out like that xD

    • @nathanmagro928
      @nathanmagro928 3 ปีที่แล้ว +165

      It was funny, he had the equation looked up in google on his screen

    • @zilberorph9879
      @zilberorph9879 3 ปีที่แล้ว +13

      Through jokes its clear who's full of shit.

    • @docbrown2045
      @docbrown2045 3 ปีที่แล้ว +12

      Yeah I felt offended too, but also I laughed like never before.

    • @goodguysaladshendelzare1919
      @goodguysaladshendelzare1919 3 ปีที่แล้ว +3

      @Nathan Magro hahahahahaha wth

    • @Ledeblogger
      @Ledeblogger 3 ปีที่แล้ว +6

      Long time I didn’t laugh with yt video

  • @beachego2654
    @beachego2654 3 ปีที่แล้ว +2249

    It was actually really funny when he was 'acting' to be smart saying 'oh, you didn't know the formula to the area of a circle?' and then the next shot is a view of his computer screen looking up the area of the circle. It was clever how he did that transition ha.

    • @SO-fb4ef
      @SO-fb4ef 3 ปีที่แล้ว +86

      I didn't even realise 😂😂😂

    • @TimBoundy
      @TimBoundy 3 ปีที่แล้ว +49

      It was so well done that I didn't even notice it

    • @arminbond2336
      @arminbond2336 3 ปีที่แล้ว

      😂😂😂

    • @vraycool
      @vraycool 3 ปีที่แล้ว +6

      What the- 😂😂😂 didn't realize that!

    • @bali5890
      @bali5890 2 ปีที่แล้ว +29

      I was about to call you captain obvious but seems like many people didn´t realize it so the comment is fine.

  • @hylash5444
    @hylash5444 3 ปีที่แล้ว +2248

    I feel like he only made this video to flex on us, especially his Patrick drawing skills

    • @aaryashah2462
      @aaryashah2462 3 ปีที่แล้ว +28

      He does that in every video

    • @jgfiugdiugiud9132
      @jgfiugdiugiud9132 3 ปีที่แล้ว +3

      @@aaryashah2462 true lol

    • @ansadahmad1958
      @ansadahmad1958 2 ปีที่แล้ว +5

      If you have been watching his videos you would know he is a major flexer😂but the good kind

    • @Phoenix-hd1tk
      @Phoenix-hd1tk 2 ปีที่แล้ว +2

      Man, i am so dumb.

    • @paolosalgo6987
      @paolosalgo6987 ปีที่แล้ว

      bruh. the boy is not humble and i love it.

  • @Ben-xj6su
    @Ben-xj6su 4 ปีที่แล้ว +3709

    They asked me this at my interview for "assistant to the cashier" at McDonald's. I aced it.

    • @YunisRajab
      @YunisRajab 4 ปีที่แล้ว +121

      Lmao the whole interview should be can you count and stand a lot?

    • @steelfalconx2000
      @steelfalconx2000 3 ปีที่แล้ว +91

      Damn you're a cashier's assistant!? Jealous!

    • @vancekangyishu
      @vancekangyishu 3 ปีที่แล้ว +116

      @@steelfalconx2000 assistant to the cashier

    • @oregano2771
      @oregano2771 3 ปีที่แล้ว +8

      @@vancekangyishu Dwight.

    • @theakatsuki2113
      @theakatsuki2113 3 ปีที่แล้ว +3

      He is kidding ,he actually knows it

  • @jorgevasquezang
    @jorgevasquezang 4 ปีที่แล้ว +3071

    3:04 I needed to pause the video because I was laughing too hard

    • @arthurcasillas2912
      @arthurcasillas2912 4 ปีที่แล้ว +10

      Same, lol

    • @ameenurrahmankhan6933
      @ameenurrahmankhan6933 4 ปีที่แล้ว +8

      Same here 😂😂😂😂😂

    • @daniel-fich
      @daniel-fich 4 ปีที่แล้ว +55

      I didn't even realize at first. That's amazing

    • @daniel-fich
      @daniel-fich 4 ปีที่แล้ว +80

      @Haze The Space Commie Look at his monitor at 3:04 ...

    • @Tom60
      @Tom60 4 ปีที่แล้ว

      Same 🤣

  • @Anshuhd
    @Anshuhd 3 ปีที่แล้ว +472

    I felt like I was being humiliated this whole time

    • @antibulletdodger101
      @antibulletdodger101 3 ปีที่แล้ว +1

      lol same here

    • @sproutdood
      @sproutdood 3 ปีที่แล้ว +7

      When you realize he actually searched up for circle area formula. 😂😂😂

    • @bjorn1724
      @bjorn1724 3 ปีที่แล้ว

      Did you like it? "50 shades of Joma Tech"-like?

    • @jhay_vine5083
      @jhay_vine5083 3 ปีที่แล้ว

      Bro 😂😂

  • @Dew_-km7gr
    @Dew_-km7gr 3 ปีที่แล้ว +85

    3:01 my math teacher every time I ask him something 😂😔👌

    • @pukhatozhimo
      @pukhatozhimo 3 ปีที่แล้ว +3

      Lol, I'm a math teacher. 😂😂

  • @Andreas92
    @Andreas92 4 ปีที่แล้ว +1931

    3:04 googling the formula lmao, nice touch

    • @pominchuang462
      @pominchuang462 4 ปีที่แล้ว +2

      lol

    • @escanorescanor9025
      @escanorescanor9025 4 ปีที่แล้ว +131

      "Oh U didn't know? Fucking idiot"

    • @l.1244
      @l.1244 4 ปีที่แล้ว +38

      Pointing out the obvious makes it unfunny.

    • @tekneiq
      @tekneiq 4 ปีที่แล้ว +41

      He got the joke boys, pack it up.

    • @hl7297
      @hl7297 4 ปีที่แล้ว +66

      @@l.1244 I didn't pay attention to that detail so his comment's still relevant

  • @chaulenguyenminh2538
    @chaulenguyenminh2538 3 ปีที่แล้ว +1463

    7:32 Actually 2.92 is closer to Pi than 3.6

    • @enki7952
      @enki7952 3 ปีที่แล้ว +82

      thats called the BrAiN GaMeS

    • @Luis-Torres
      @Luis-Torres 3 ปีที่แล้ว +129

      Oh you didn't know? *chuckles* idiot.

    • @darienrafaelmarquezvazquez7694
      @darienrafaelmarquezvazquez7694 3 ปีที่แล้ว +63

      @@Luis-Torres "Google: What is more close to pi, 2.92 or 3.6????????????????"

    • @mathnetic7511
      @mathnetic7511 3 ปีที่แล้ว +1

      I saw that too. Xd

    • @Priestessfly
      @Priestessfly 3 ปีที่แล้ว +3

      damn brilliant

  • @rohitniroula
    @rohitniroula 3 ปีที่แล้ว +10

    5:32 that googling google to go to Google killed me 🤣🤣🤣🤣

  • @va9if
    @va9if 3 ปีที่แล้ว +152

    I thought he wasn't serious when he said "calculate π"

  • @tyto125
    @tyto125 4 ปีที่แล้ว +299

    This dude is flexed so hard that youtube had no other choice but to recommend this to everyone

  • @Dgsrgv
    @Dgsrgv 4 ปีที่แล้ว +1259

    honestly, sometimes i find it really hard to tell whether joma is actually being serious to straight up trolling. Cuz him having a serious face can easily fool someone gullible like me.

    • @barryrims9098
      @barryrims9098 4 ปีที่แล้ว +20

      That's cuz ur stupid it's ok

    • @Dgsrgv
      @Dgsrgv 4 ปีที่แล้ว +107

      @@barryrims9098 its ok i know u aint got friends

    • @Dgsrgv
      @Dgsrgv 4 ปีที่แล้ว +43

      @@choiceindot its ok i know your a low energy human being trying to find the meaning of your existence ill just give it to you

    • @Dgsrgv
      @Dgsrgv 4 ปีที่แล้ว +20

      @@choiceindot your actually an idiot lol

    • @Dgsrgv
      @Dgsrgv 4 ปีที่แล้ว +36

      @@choiceindot you implicitly admitted you`re an idiot lol nice job idiot

  • @yogendraadhikari4275
    @yogendraadhikari4275 3 ปีที่แล้ว +58

    If someone asks me this kind of question, I would just walk away...

    • @jhay_vine5083
      @jhay_vine5083 3 ปีที่แล้ว

      Facts bro 😂😂😂

    • @faizanali193
      @faizanali193 3 ปีที่แล้ว +5

      To be honest,
      If someone applies for data scientist positions and doesn't even know the basic Monte Carlo, then he should definitely walk away. So many ML/DL junkies wanna be a data scientist these days, can't even pass a basic statistics test...

    • @stm12p
      @stm12p 2 ปีที่แล้ว

      @@faizanali193 who the hell claims themselves DS guy if they don't know Monte Carlo? i mean, you could do it without any coding skill.

  • @vejovim
    @vejovim 3 ปีที่แล้ว +147

    Please do more of these 10 minute videos with interesting questions and their answers! This would be a great format to learners. As soon as you posed the question, I hopped on pycharm and coded it up! It was fun!

  • @tiankaixiong2340
    @tiankaixiong2340 4 ปีที่แล้ว +474

    That's like the very first example any professor would show when teaching about Monte Carlo.

    • @TrioLOLGamers
      @TrioLOLGamers 4 ปีที่แล้ว +7

      My teacher inserted that in an exercise for the test... It was cool, but later I discovered that he copied everything in the tests from forums... So he knew only few things... Not as teacher at the University

    • @CamaradaArdi
      @CamaradaArdi 4 ปีที่แล้ว +8

      @@TrioLOLGamers at least here in Spain you have to be a doctor to be a professor

    • @TrioLOLGamers
      @TrioLOLGamers 4 ปีที่แล้ว

      @@CamaradaArdi really?

    • @srgk26
      @srgk26 4 ปีที่แล้ว +2

      @@CamaradaArdi Isn't that how it is everywhere?

    • @srgk26
      @srgk26 4 ปีที่แล้ว

      @@jarolrivera640 I suppose you're from the US? Don't know how it is there, I know PhD students also teach but didn't know they're called professors too. I'm in the UK, and here only a fraction of PhD holders even have a chance of possibly becoming professor. It's the highest "rank" you can have in the academic ladder, and even that's not tenured. If you don't produce results in a certain time, you'll be asked to leave. Though by that time, you're probably quite crazy about the field you would probably produce results. With regard to lecturing, at research intensive universities would normally be working for at least 5-10 years or so to be a lecturer. Not sure if this is a good setup but that's how it is here.

  • @vasiliynkudryavtsev
    @vasiliynkudryavtsev 3 ปีที่แล้ว +17

    Fun fact is that you don't need the random function to compute with this technique.
    Just using points on the grid would result the same. E.g. double loop for x and y.
    The finer the grid - the more precise is the result.

    • @bastiaan9127
      @bastiaan9127 3 ปีที่แล้ว +2

      That's what I was thinking. Regular grids should even be slightly more accurate than random numbers. But be careful to exclude two of the four borders. Starting off with random numbers is probably just to confuse applicants, or test their ability to generalize and simplify.

    • @fruitygranulizer540
      @fruitygranulizer540 2 ปีที่แล้ว +3

      yea but the point of the original question is to find pi with a bunch of seemingly ranodm numbers. if the question mentioned a grid, its a bit easier to come up with the solution.

    • @jeffery_tang
      @jeffery_tang 9 หลายเดือนก่อน

      you would have to deal with edge cases like what if the point was right on the line, but that's probably a trivial solution to it

  • @lexus7154
    @lexus7154 3 ปีที่แล้ว +1

    Omg, i love this guy!!
    I'm a data science major and I am so happy I stumbled across your channel. I'm gonna sign up with your services.

  • @ShibayanMondal
    @ShibayanMondal 3 ปีที่แล้ว +22

    2:58 The greatest sense of humour I have ever seen!

  • @abeecee
    @abeecee 4 ปีที่แล้ว +33

    More of these pls I love them, also the coding explanations really help beginners. Love u joma

  • @TrueZenquiorra
    @TrueZenquiorra 4 ปีที่แล้ว +23

    Hey Joma! I really loved this content, gonna share with my friends to blow their minds.

  • @IgnisZephyr
    @IgnisZephyr 3 ปีที่แล้ว +121

    There is another way (more computing intensive though), you can transform the numbers into integer and check if they are coprime. The probability that two integers are coprime is equal to 6/π^2. And boom, you have a solution that is way longer to run

    • @kolbstar
      @kolbstar 3 ปีที่แล้ว +5

      That's using a lot more than just a uniform random variable generator. You're using multiplication, square root, and the definition of coprime.

    • @StrangerHappened
      @StrangerHappened 2 ปีที่แล้ว +15

      @@kolbstar the random generator is already ridiculously overboard, unnecessary and slow for pi calculation. So the root comment is just upping the game. And I am sure there are ways to calculate pi that are even slower. There HAS to be a competition for the slowest algorithm.

    • @kolbstar
      @kolbstar 2 ปีที่แล้ว +38

      @@StrangerHappened I planted a tree in my back yard. I will wait for it to grow to maturity, cut it down, dry it, put it on a lathe to make a rod, then measure its circumference and diameter.

    • @thaituanly8955
      @thaituanly8955 2 ปีที่แล้ว +1

      how bout
      - Using a presentation of a circle (center (0,0), r = 1) in a cartesian coordinate system (which would be x^2 + y^2 = r^2)
      - Find the area that is bound by the circle in the first quarter and the x and y axis using integral, and this area would be 1/4 of a circle
      - Calculate Pi from that area
      This way (if works) will require 0 call for random(), and gives you constant runtime + better accuracy.

    • @astronemir
      @astronemir 2 ปีที่แล้ว

      @@StrangerHappened that’s not true the random generator is a pretty damn good empirical way of calculating pi.

  • @javand86
    @javand86 2 ปีที่แล้ว +1

    The fact that I'm doing my homework and its a very similar problem to this, so I'm using it for a reference. So glad I watched this earlier, great content man!

  • @jdmaine51084
    @jdmaine51084 4 ปีที่แล้ว +24

    Dude... this is the second video of yours I've watched, and so far they're both hilarious. I genuinely thought you were calling me an idiot, and then the next cut shows the area of a circle Google results on screen hahaha.

  • @omegacon4
    @omegacon4 4 ปีที่แล้ว +6

    This was a outstanding video. Thanks for making it. I'm just starting to learn Python so appreciate the coding segment in this video as well.

  • @CollegeBoyDeon
    @CollegeBoyDeon 3 ปีที่แล้ว +34

    “Now calculate the mass of the sun” 💀😂 I died

  • @badunius_code
    @badunius_code 3 ปีที่แล้ว +6

    8:40 you could also calculate root mean square of M estimates of size N, and get better precision while maintaining O(n + m) complexity

  • @pmoe7
    @pmoe7 4 ปีที่แล้ว +200

    I genuinely died when he searched up the area of the circle 😂😂😂

  • @Governorrr
    @Governorrr 4 ปีที่แล้ว +417

    Joma: *gives function total number of points as n*
    Joma: *proceeds to calculate total number of points as num_point_total*

    • @phamtuanbinh9655
      @phamtuanbinh9655 3 ปีที่แล้ว +10

      @Light Myst :v Then why won't he name the func param like that. It's simply because of the order of his thoughts.

    • @icaruscorp1529
      @icaruscorp1529 3 ปีที่แล้ว +28

      I think it’s probably a habit from working on bigger projects, where a single letter variable isn’t really a good idea if multiple people work on it

    • @tutankhamen5080
      @tutankhamen5080 3 ปีที่แล้ว +3

      Legit happens to me

    • @soumojitchowdhury151
      @soumojitchowdhury151 2 ปีที่แล้ว +11

      @@icaruscorp1529 but its a waste of time. You are passing n to the function and also counting it in side the loop, it adds extra computation for literally no reason

    • @bo17age
      @bo17age 2 ปีที่แล้ว

      you got me b*tch!

  • @mgancarzjr
    @mgancarzjr 3 ปีที่แล้ว +16

    When you're finished, you can show them another way and name-drop Euler for extra credit.
    double x = 0;
    for(int i = 1; i < some_limit; i++) {
    x += 1 / (i * i)
    }
    print(sqrt(x * 6)); // fixed by Eutu Salli
    The other, modern, fast formulas (Ramunajan and Chudnovsky) include polynomials and factorials. This would either require using libraries or writing your own functions.

    • @thaituanly8955
      @thaituanly8955 2 ปีที่แล้ว

      how bout
      - Using a presentation of a circle (center (0,0) r = 1) in a cartesian coordinate system (which would be x^2 + y^2 = r^2)
      - Find the area that is bound by the circle in the first quarter and the x and y axis using integral, and this area would be 1/4 of a circle
      - Calculate Pi from that area
      This way (if works) will require 0 call for random(), and gives you constant runtime.

    • @mgancarzjr
      @mgancarzjr 2 ปีที่แล้ว +1

      @@thaituanly8955 the integral of sqrt(r^2 - x^2)dx is
      0.5 * (x * sqrt(r^2 - x^2) + r^2 * arctan(x / sqrt(r^2 - x^2)))
      Assuming you can pull this formula out of your head or derive it (I cannot), the arctan() function becomes a problem. If you can't code an arctan function, you'll need to rely on a math library. If you can access the math library, looking up pi will be far faster.
      Converting to the polar coordinate system creates a far easier integration and avoids arctan, but then you're integrating in radians which require the use of pi.

    • @mgancarzjr
      @mgancarzjr 2 ปีที่แล้ว

      @@thaituanly8955 you can do a Reimann sum where you accumulated the areas of very thin rectangles from 0 to 1 whose heights are the sqrt(1 - x.position^2).
      The issue with that is the same issue with the Monte Carlo simulation in that you're calling a sqrt function n times which is slow.

    • @etusax
      @etusax 2 ปีที่แล้ว +1

      Are you sure your formula there is correct? I implemented your solution and got results pretty far from pi (around 7,7). I'm pretty sure I triple checked the implementation to be correct.

    • @mgancarzjr
      @mgancarzjr 2 ปีที่แล้ว

      @@etusax you are correct. It should be sqrt(x * 6). I posted a link to a working implementation on an online compiler/debugger, but TH-cam deleted the post. I must be on a naughty list.

  • @yourfuneral
    @yourfuneral ปีที่แล้ว

    I like the content and appreciate how you guide through the act of creation in a way that shows quick and easy how to connect dots, where to look and how to improve, and all in a funny, entertaining and overall very polished looking way. I feel betrusted in my intellect but yet not overestimated :D
    First content I saw of yours was the apple-type blinds commercial on your other channel.

  • @AashishMishra_Nygma
    @AashishMishra_Nygma 4 ปีที่แล้ว +134

    1:40 to 1:43 can cure depression, end wars and achieve world peace

  • @TheJustinmulli
    @TheJustinmulli 4 ปีที่แล้ว +8

    Better solution without the random function (could suggest both solutions, although they never said use the random function anyway)
    Calculate the area under the first quadrant of the unit circle curve using a riemann sum and multiply it by 4
    x = np.linspace(0,1,1000)
    pi_approx = sum(np.sqrt(1-x**2)*x[1])*4
    Also for the solution using the random function just create arrays of random numbers and perform the operations once instead of looping:
    x = random(n)
    y = random(n)
    pi_approx = (sum(x**2+y**2

  • @wristocrat
    @wristocrat ปีที่แล้ว

    Easily the funnest programming tutorial I've ever seen, great information too

  • @Hyttelus
    @Hyttelus 2 ปีที่แล้ว +14

    This was literally one of the exam question in a programming and microcontroller course I took this semester.

  • @Oscarrudnas
    @Oscarrudnas 4 ปีที่แล้ว +34

    I was going to comment: I could learn this all day if you would teach it.
    And then joma academia.
    Nice thanks

  • @firepro20
    @firepro20 4 ปีที่แล้ว +11

    I really love learning from this channel, it makes learning complicated stuff fun, with a perfect blend of humour. Also, I really like that Patrick, let the artist know it's great work, whoever it might be.

  • @amaizel
    @amaizel 3 ปีที่แล้ว +5

    This is one of the first cases of Monte Carlo you learn! Very simple and elegant solution to estimate Pi. The funny thing is that you can do the same calculation using a cardboard, a baby powder and a scale!

  • @jepoyburner
    @jepoyburner 3 ปีที่แล้ว +8

    This is the classic Monte Carlo introduction problem. Ptsd to my thesis days.

  • @danielfournier6015
    @danielfournier6015 3 ปีที่แล้ว +11

    My first thought was to use the randomly generated points to do numerical integration. I had to first generate points, then sort them, then integrate numerically using trapezoidal sums (average of upper and lower sums). Since i used a simple sorting algorithm that would be in n^2 time it doesn’t seem to be a very efficient solution. I like the way you did it without getting overly complicated. I’ve spent so much time doing heavy pure maths proofs so my brain must have been stuck up there and missed the easier solution. Good job!

    • @Philgob
      @Philgob 11 หลายเดือนก่อน

      how the fuck is this your first thought

  • @pablogarin
    @pablogarin 4 ปีที่แล้ว +10

    in python:
    use command help('modules') to see all modules installed,
    use command help(module) to see documentation,
    use command dir(module) to see available commands

  • @MoritzWallis
    @MoritzWallis 3 ปีที่แล้ว

    This is super smart. Never would have thought of this.

  • @net2cn
    @net2cn 2 ปีที่แล้ว

    I've done this on my TI graphing calculator back when I was in high school and it was a ton of fun learning about the Monte Carlo method.

  • @angry_moose94
    @angry_moose94 3 ปีที่แล้ว +4

    Hey btw if anyone is trying to plot the points in the circle graph like I did, remember that the points range from 0-1. So only in the upper right quadrant. If you want to plot them in a full circle, you have to change the range from -1 to 1.

  • @stevenspearman5697
    @stevenspearman5697 4 ปีที่แล้ว +63

    5:27 - You went to google.com to google google and clicked on the first google link to take you to google. BIG BRAIN!

  • @jomardomingos7886
    @jomardomingos7886 3 ปีที่แล้ว

    Your sense of humor is great!

  • @mionszu
    @mionszu 2 ปีที่แล้ว +1

    Wow, I remember that. I had it once in my high school classes. Good to know it can be an interview question

  • @braer240
    @braer240 2 ปีที่แล้ว +5

    I swear I laugh the most watching your videos. So many programming/coding/tech channels try to be funny and it’s just awkward. But joma always delivers

  • @jamiejackson2144
    @jamiejackson2144 3 ปีที่แล้ว +3

    Instead of using another variable incrementing for total points, you can directly use "n" which came as input argument.

  • @--.--
    @--.-- 3 ปีที่แล้ว

    OMG! This was so useful and also very fun, thanks!

  • @jaycee6689
    @jaycee6689 2 ปีที่แล้ว

    I actually understood this omg. Thanks Joma!!! thanks for the vid
    might also add that youre “weirdly” entertaining like you know how to do it somehow

  • @hashimalsmael3396
    @hashimalsmael3396 3 ปีที่แล้ว +5

    3:04 I see what you did there I nearly died laughing LMFAO

  • @odikuhschrank7936
    @odikuhschrank7936 2 ปีที่แล้ว +3

    Hey! I wanted to add a little side note for those that are interested in the maths behind it.
    Lets imagine that we are throwing arrows at a square of side length 1 (Lets call it "A").
    Then the Probability of our arrow landing in the Part of the circle that intersects the square (Lets call it "C") is: Area(C) / Area(A) = pi/4 / 1 = pi/4.
    Now let X_k be a random variable, with X_k : [0,1)^2 -> {0 , 1} | (x, y) -> { 1, if |(x,y)| < 1 ; 0 in any other case
    We therefore have: P(X_k = 1) = pi/4, P(X_k = 0) = 1 - pi/4 => Expected Value: E(X_k) = P(X_k = 1) * 1 + P(X_k = 0) * 0 = pi/4
    X_k represents our k-th throw. You get 1$ if your arrow lands in the circle and 0$ if it doesnt.
    We now use the "Weak law of large numbers" which states that 1/N * ( sum(X_k) from 1 to N ) -> E(X_k). Here we are just taking the mean of all our payments gained from throwing arrows. This converges (in probability) towards E(X_k) = pi/4.
    By using the markov-inequality we can even calculate the minimum number of throws we need to have a certain probality that we are closer than a>0 to pi, for any a>0.

  • @soumojitchowdhury151
    @soumojitchowdhury151 2 ปีที่แล้ว

    That logic of thinking with the graph is where the main clue is... Awesome idea

  • @bryanfeliciano4102
    @bryanfeliciano4102 3 ปีที่แล้ว +365

    I look at coding interview questions everytime I wanna feel stupid
    Edit: I learned python, javascript,and c++ and algos still make me feel stupid 😂.

    • @modellking
      @modellking 3 ปีที่แล้ว +13

      tbh most usual interview questions are easy at companies outside of FANG and where the bosses understand anything about engineering. (Had some during the last year)

    • @Heroseuss
      @Heroseuss 3 ปีที่แล้ว +1

      Lmaoo

    • @DrRAZI99
      @DrRAZI99 3 ปีที่แล้ว

      Lol

    • @bryanfeliciano4102
      @bryanfeliciano4102 3 ปีที่แล้ว +1

      @@DrRAZI99 glad that made you giggle 😂

    • @nyb_ok
      @nyb_ok 2 ปีที่แล้ว

      Its ok. Noone can know everything.

  • @jeremyshaw1
    @jeremyshaw1 4 ปีที่แล้ว +4

    Interesting question, thanks!
    This took me way longer to program than it should have (nearly 30min in C). I did learn that floats can get less precise as the numbers get more massive (which I somehow forget; it's obvious), and to use doubles in this case. My INT_MAX iterations got me to 3.141575.

  • @tarunpatel8168
    @tarunpatel8168 3 ปีที่แล้ว +47

    Joma you are amazing, I laughed hard at 5:30 😂😂
    Amazing content too

  • @Concon237
    @Concon237 3 ปีที่แล้ว

    Great video! This is a nice example of a Monte Carlo method, pretty cool :)

  • @derrickmelton5844
    @derrickmelton5844 3 ปีที่แล้ว

    Determining whether random points fall in a circle seems more convoluted than it needs to be.
    A random point between 0 and 1 used as just one x or y component is sufficient since you can then derive the other component using pythagorean theorem and do 1 - the value squared and take the square root of that.
    Then you can use the property that triangles have pi radians and derive all the angles in radians from the values using simple trig.
    Sum them together, and you have pi.

  • @calvintran6544
    @calvintran6544 3 ปีที่แล้ว +4

    6:08 when he typed in x^2 first before x**2 😂 gets me every time

  • @frankpujo8073
    @frankpujo8073 3 ปีที่แล้ว +4

    2:52 don't mind me, just wanted the golden moment of the video to replay

  • @macplays4450
    @macplays4450 3 ปีที่แล้ว

    Your videos are awesome man!

  • @mattbown
    @mattbown 3 ปีที่แล้ว

    Watching your video, and following along makes me feel smarter lol
    Thanks for the content

  • @Glendragon
    @Glendragon 3 ปีที่แล้ว +7

    first number: 3.6 (0,46 away)
    second number: 2.92 (0,22 away)
    Joma: "that is not more accurate"

  • @PriyanshGupta2906
    @PriyanshGupta2906 4 ปีที่แล้ว +39

    This is called the Montecarlo simulation

  • @AkashGupta-rw4vm
    @AkashGupta-rw4vm 2 ปีที่แล้ว +1

    3:00 Calling you a fu*kind idiot, and having the browser window opened in which he searched for the same is just hilarious 🤣🤣🤣

  • @l.meyers3348
    @l.meyers3348 2 ปีที่แล้ว

    “Fuckin idiot”…both makes me laugh and cry. Genius, just genius!

  • @muhammadwasi5460
    @muhammadwasi5460 4 ปีที่แล้ว +32

    Dude this man is my favourite...except he shows up on my interview day lamo..i'm dead...

  • @francoisa3231
    @francoisa3231 4 ปีที่แล้ว +61

    You can actually just divide by n

    • @jomakaze
      @jomakaze  4 ปีที่แล้ว +27

      Yea oops

    • @3lietechhack646
      @3lietechhack646 4 ปีที่แล้ว +1

      How? Could you please explain?

    • @francoisa3231
      @francoisa3231 4 ปีที่แล้ว +8

      nb_loop = 10000000
      nb_point = 0
      x = 0
      y = 0
      for _ in range(nb_loop):
      y = x
      x = random.uniform(0,1)
      if x**2 +y**2

    • @Hellopiermy
      @Hellopiermy 4 ปีที่แล้ว +13

      Super fast way:
      from numpy import sum, random as r
      N = 10000 (your choice)
      sum(r.rand(N)**2 + r.rand(N)**2 < 1) * 4.0 / N

    • @felipemotorhead
      @felipemotorhead 4 ปีที่แล้ว +1

      It doesn't matter, I'm not going to write any of these calcs for my applications anyways

  • @ariadnamartinleon4217
    @ariadnamartinleon4217 3 ปีที่แล้ว +1

    please, do more videos like this one, with actual coding, it helps a lot!

  • @luchodasavage
    @luchodasavage 3 ปีที่แล้ว +7

    I don't even like math, but can't stop watching videos of this dude

  • @johmarjac
    @johmarjac 4 ปีที่แล้ว +8

    Jesus, you got me when searching in google for google lmao.. i spit in my cereal

  • @UmarMash
    @UmarMash 4 ปีที่แล้ว +32

    3:04 i lit laughed so hard... after all the bragging....lol

  • @abdelrhmandameen2215
    @abdelrhmandameen2215 3 ปีที่แล้ว

    This was very satisfying thanks.

  • @NStripleseven
    @NStripleseven 3 ปีที่แล้ว

    You could do the same thing with a smaller circle, checking the distance to 0.5, 0.5 instead of the origin and including points within 0.5 of it.

  • @carlavntr
    @carlavntr 4 ปีที่แล้ว +6

    What kind of program do you use to draw like that? Thank you you're awesome

  • @ikersanchez8222
    @ikersanchez8222 3 ปีที่แล้ว +6

    3:05 I genuinly almost shit myself just by laughing lmao

  • @Saladmints
    @Saladmints 3 ปีที่แล้ว

    Based off of just drawing the quadrant with all the dots: you find the proportion of points where x^2 + y^2

  • @reardoor
    @reardoor 3 ปีที่แล้ว

    I just love how many subtle things like

  • @Srtotalo
    @Srtotalo 4 ปีที่แล้ว +7

    All the knowledge inside this piece of humor, I had to stop and laugh for every joke. Really well done 👏🏼

  • @bogdns
    @bogdns 3 ปีที่แล้ว +10

    num_point_total is really useful( “n” is useless)

  • @Whiteleon13
    @Whiteleon13 2 ปีที่แล้ว

    Bro your humor is real epic love it, not even cringe

  • @susmitobhattacharyya1668
    @susmitobhattacharyya1668 ปีที่แล้ว

    You are really amazing.❤
    Everything you do is just amazing.

  • @ameysawant2301
    @ameysawant2301 4 ปีที่แล้ว +5

    Why no one is talking about how funny at the same time educational his videos are😂😂😂😂😂😂😂😂😂 !!!! You are doing a great job JOMA ✨✨✨✨🔥🔥🔥🔥🔥

  • @Martyballin
    @Martyballin 4 ปีที่แล้ว +37

    These questions are good for boosting the ego of the interviewer, nothing more.

    • @jeremyshaw1
      @jeremyshaw1 4 ปีที่แล้ว +6

      Supposedly, they should be near impossible questions that aren't realisitically solvable within the confines of an interview, and the purpose is to show the approach and problem solving of the interviewee. A kobayashi maru, perhaps. Obviously, it doesn't quite work that way.

    • @marwanassih3582
      @marwanassih3582 4 ปีที่แล้ว +4

      It's a classical problem. making an approximation of pi using proba. here we used the monte carlo method.

    • @ignaciosavi7739
      @ignaciosavi7739 4 ปีที่แล้ว +1

      @@jeremyshaw1 i solved it in 5 mins.

    • @daniele4839
      @daniele4839 3 ปีที่แล้ว +3

      @@ignaciosavi7739 I solved it in 2

    • @ignaciosavi7739
      @ignaciosavi7739 3 ปีที่แล้ว

      @@daniele4839 great job!

  • @albertoz.473
    @albertoz.473 3 ปีที่แล้ว

    Love your sense of humor 😅👍 Great video, as usual 😊

  • @mitch7w
    @mitch7w 3 ปีที่แล้ว

    This was great thanks!

  • @callforjhed
    @callforjhed 4 ปีที่แล้ว +85

    when he started typing "p" in google all the search results and auto texts were blurred and the titles are long and there are dashes and xs and stuffs.... 😆 just kidding. nice video by the way cheers!

  • @toaderadrian3146
    @toaderadrian3146 4 ปีที่แล้ว +17

    2:58 ,my brain after exams

  • @otaviovasconcelos6315
    @otaviovasconcelos6315 2 ปีที่แล้ว

    Man I love your videoooss!!!

  • @venkateshelumalai3670
    @venkateshelumalai3670 3 ปีที่แล้ว +2

    Here for area of circle you have to r/2 as a radius and r as a side of square, for randomizing the number from 0 to 1 , otherwise you have to randomize -1 to 1=> for clarity 🤙

  • @EmissaryOfSmeagol
    @EmissaryOfSmeagol 4 ปีที่แล้ว +4

    pdf of given funciton: p(x)=1, x in [0,1], 0 otherwise.
    integral(0,1) 4*arctan(p(x)) dx = pi

  • @jeps7688
    @jeps7688 4 ปีที่แล้ว +90

    5:29 thats me having trust issue googling google.

  • @CharlesSmith-vk8co
    @CharlesSmith-vk8co 3 ปีที่แล้ว

    You have a great sense of humour,really can relate to it :D

  • @smb1397
    @smb1397 ปีที่แล้ว +1

    you could also use the Central Limit Theorem and the fact that there's pi in the PDF of the Normal Distribution. actually there's a huge no. of places pi shows up in math

  • @bluehornet6752
    @bluehornet6752 3 ปีที่แล้ว +5

    Very cool algorithm. Messing around with this a bit, and implemented it in C++ and C# as well. The results end up being very close to the actual value of Pi, just as shown here in the video. The cool this is that the C# version executes just about as fast as the C++ version does. I guess that's to be expected though, given that the heavy-lifting is done in the loop.

  • @alimostafaabdelghaffar4549
    @alimostafaabdelghaffar4549 4 ปีที่แล้ว +38

    me: damn this guy is smart i don't know how to calculate this
    me after joma googles google: visible confusion

    • @liveyourlifenow7935
      @liveyourlifenow7935 4 ปีที่แล้ว

      What He always use to code is PyCharm or python studio ?
      what does He use now ? any one can tell Me plz ?

    • @phoenixstormjr.1018
      @phoenixstormjr.1018 4 ปีที่แล้ว +1

      Area of square minus area of circle. Because there is 4 corners divide by 4. Why do programmers always overcomplicate things?
      Finding pi. Is easier. Make white circle. Make random radius. If point is white count it. Count all white points. That's area. Area divided by radius^2 = pi.

    • @heartofthefluff1026
      @heartofthefluff1026 3 ปีที่แล้ว

      If i remember correctly, that website it repl.it

    • @phoenixstormjr.1018
      @phoenixstormjr.1018 3 ปีที่แล้ว

      @@Ali-gh7rj i think this channel is more of an overcomplicated joke channel for people that actually know what theyre doing.

    • @phoenixstormjr.1018
      @phoenixstormjr.1018 3 ปีที่แล้ว

      @@Ali-gh7rj hm. Thats another easy way to do it. But circumference must be huge to get an accurate result.

  • @kiminotoriko6178
    @kiminotoriko6178 3 ปีที่แล้ว

    That's awesome solution! I never thought that, I mean out of my guess..
    Awesome!