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

  Рет қаралды 1,714,218

Joma Tech

Joma Tech

Күн бұрын

Пікірлер: 2 100
@jomakaze
@jomakaze 4 жыл бұрын
Check out my second channel: kzbin.info/door/WhwybsQg-EeBJpsqtmbscw for snackable educational content
@Ultrajamz
@Ultrajamz 4 жыл бұрын
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?
@ppcamps
@ppcamps 4 жыл бұрын
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 жыл бұрын
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 4 жыл бұрын
num_point_total will be n 😉. You should try with 3 or more dimensions. Monte Carlo is made for bigger dimensions.
@hylash5444
@hylash5444 3 жыл бұрын
I feel like he only made this video to flex on us, especially his Patrick drawing skills
@aaryashah2462
@aaryashah2462 3 жыл бұрын
He does that in every video
@jgfiugdiugiud9132
@jgfiugdiugiud9132 3 жыл бұрын
@@aaryashah2462 true lol
@ansadahmad1958
@ansadahmad1958 3 жыл бұрын
If you have been watching his videos you would know he is a major flexer😂but the good kind
@Phoenix-hd1tk
@Phoenix-hd1tk 3 жыл бұрын
Man, i am so dumb.
@paolosalgo6987
@paolosalgo6987 2 жыл бұрын
bruh. the boy is not humble and i love it.
@Waiel
@Waiel 4 жыл бұрын
My favorite interview question is *“What’s your name?”*
@moustafadarwish3674
@moustafadarwish3674 3 жыл бұрын
and i sometimes get it wrong
@DrRAZI99
@DrRAZI99 3 жыл бұрын
Thats a pretty hard question
@КостяПак-я5я
@КостяПак-я5я 3 жыл бұрын
Such a tough question.
@namenotavailable9989
@namenotavailable9989 3 жыл бұрын
Too bad. My name is harder to pronounce.
@pipedownandeatyourpudding2986
@pipedownandeatyourpudding2986 3 жыл бұрын
its my favorite as well, but it can get difficult at times
@beachego2654
@beachego2654 3 жыл бұрын
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 жыл бұрын
I didn't even realise 😂😂😂
@TimBoundy
@TimBoundy 3 жыл бұрын
It was so well done that I didn't even notice it
@arminbond2336
@arminbond2336 3 жыл бұрын
😂😂😂
@vraycool
@vraycool 3 жыл бұрын
What the- 😂😂😂 didn't realize that!
@bali5890
@bali5890 3 жыл бұрын
I was about to call you captain obvious but seems like many people didn´t realize it so the comment is fine.
@joeface448
@joeface448 3 жыл бұрын
"Fuckin' idiot..." made me almost cry from laughing so hard. You bastard, gotta call me out like that xD
@nathanmagro928
@nathanmagro928 3 жыл бұрын
It was funny, he had the equation looked up in google on his screen
@zilberorph9879
@zilberorph9879 3 жыл бұрын
Through jokes its clear who's full of shit.
@docbrown2045
@docbrown2045 3 жыл бұрын
Yeah I felt offended too, but also I laughed like never before.
@goodguysaladshendelzare1919
@goodguysaladshendelzare1919 3 жыл бұрын
@Nathan Magro hahahahahaha wth
@Ledeblogger
@Ledeblogger 3 жыл бұрын
Long time I didn’t laugh with yt video
@vejovim
@vejovim 4 жыл бұрын
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!
@Ben-xj6su
@Ben-xj6su 4 жыл бұрын
They asked me this at my interview for "assistant to the cashier" at McDonald's. I aced it.
@YunisRajab
@YunisRajab 4 жыл бұрын
Lmao the whole interview should be can you count and stand a lot?
@steelfalconx2000
@steelfalconx2000 4 жыл бұрын
Damn you're a cashier's assistant!? Jealous!
@vancekangyishu
@vancekangyishu 4 жыл бұрын
@@steelfalconx2000 assistant to the cashier
@oregano2771
@oregano2771 4 жыл бұрын
@@vancekangyishu Dwight.
@theakatsuki2113
@theakatsuki2113 4 жыл бұрын
He is kidding ,he actually knows it
@chaulenguyenminh2538
@chaulenguyenminh2538 4 жыл бұрын
7:32 Actually 2.92 is closer to Pi than 3.6
@enki7952
@enki7952 4 жыл бұрын
thats called the BrAiN GaMeS
@Luis-Torres
@Luis-Torres 4 жыл бұрын
Oh you didn't know? *chuckles* idiot.
@darienrafaelmarquezvazquez7694
@darienrafaelmarquezvazquez7694 4 жыл бұрын
@@Luis-Torres "Google: What is more close to pi, 2.92 or 3.6????????????????"
@mathnetic7511
@mathnetic7511 4 жыл бұрын
I saw that too. Xd
@Priestessfly
@Priestessfly 4 жыл бұрын
damn brilliant
@jorgevasquezang
@jorgevasquezang 4 жыл бұрын
3:04 I needed to pause the video because I was laughing too hard
@arthurcasillas2912
@arthurcasillas2912 4 жыл бұрын
Same, lol
@ameenurrahmankhan6933
@ameenurrahmankhan6933 4 жыл бұрын
Same here 😂😂😂😂😂
@daniel-fich
@daniel-fich 4 жыл бұрын
I didn't even realize at first. That's amazing
@daniel-fich
@daniel-fich 4 жыл бұрын
@Haze The Space Commie Look at his monitor at 3:04 ...
@Tom60
@Tom60 4 жыл бұрын
Same 🤣
@mgancarzjr
@mgancarzjr 4 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
@@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 3 жыл бұрын
@@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 3 жыл бұрын
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 3 жыл бұрын
@@etusax you are correct. It should be sqrt(x * 6). I posted a link to a working implementation on an online compiler/debugger, but KZbin deleted the post. I must be on a naughty list.
@vasiliynkudryavtsev
@vasiliynkudryavtsev 3 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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 Жыл бұрын
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
@Andreas92
@Andreas92 4 жыл бұрын
3:04 googling the formula lmao, nice touch
@pominchuang462
@pominchuang462 4 жыл бұрын
lol
@escanorescanor9025
@escanorescanor9025 4 жыл бұрын
"Oh U didn't know? Fucking idiot"
@l.1244
@l.1244 4 жыл бұрын
Pointing out the obvious makes it unfunny.
@tekneiq
@tekneiq 4 жыл бұрын
He got the joke boys, pack it up.
@hl7297
@hl7297 4 жыл бұрын
@@l.1244 I didn't pay attention to that detail so his comment's still relevant
@tyto125
@tyto125 4 жыл бұрын
This dude is flexed so hard that youtube had no other choice but to recommend this to everyone
@Dgsrgv
@Dgsrgv 4 жыл бұрын
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 жыл бұрын
That's cuz ur stupid it's ok
@Dgsrgv
@Dgsrgv 4 жыл бұрын
@@barryrims9098 its ok i know u aint got friends
@Dgsrgv
@Dgsrgv 4 жыл бұрын
@@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 жыл бұрын
@@choiceindot your actually an idiot lol
@Dgsrgv
@Dgsrgv 4 жыл бұрын
@@choiceindot you implicitly admitted you`re an idiot lol nice job idiot
@IgnisZephyr
@IgnisZephyr 3 жыл бұрын
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 жыл бұрын
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 3 жыл бұрын
@@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 3 жыл бұрын
@@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 3 жыл бұрын
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 3 жыл бұрын
@@StrangerHappened that’s not true the random generator is a pretty damn good empirical way of calculating pi.
@Anshuhd
@Anshuhd 4 жыл бұрын
I felt like I was being humiliated this whole time
@antibulletdodger101
@antibulletdodger101 4 жыл бұрын
lol same here
@sproutdood
@sproutdood 3 жыл бұрын
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 😂😂
@TheJustinmulli
@TheJustinmulli 4 жыл бұрын
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
@tiankaixiong2340
@tiankaixiong2340 4 жыл бұрын
That's like the very first example any professor would show when teaching about Monte Carlo.
@TrioLOLGamers
@TrioLOLGamers 4 жыл бұрын
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 жыл бұрын
@@TrioLOLGamers at least here in Spain you have to be a doctor to be a professor
@TrioLOLGamers
@TrioLOLGamers 4 жыл бұрын
@@CamaradaArdi really?
@srgk26
@srgk26 4 жыл бұрын
@@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.
@AashishMishra_Nygma
@AashishMishra_Nygma 4 жыл бұрын
1:40 to 1:43 can cure depression, end wars and achieve world peace
@AashishMishra_Nygma
@AashishMishra_Nygma 4 жыл бұрын
don't believe me? click it back to back
@gabrielrezcp1788
@gabrielrezcp1788 3 жыл бұрын
@@AashishMishra_Nygma shure i do
@badunius_code
@badunius_code 4 жыл бұрын
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
@therealdanielfournier
@therealdanielfournier 3 жыл бұрын
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 Жыл бұрын
how the fuck is this your first thought
@Governorrr
@Governorrr 4 жыл бұрын
Joma: *gives function total number of points as n* Joma: *proceeds to calculate total number of points as num_point_total*
@phamtuanbinh9655
@phamtuanbinh9655 4 жыл бұрын
@ :v Then why won't he name the func param like that. It's simply because of the order of his thoughts.
@icaruscorp1529
@icaruscorp1529 4 жыл бұрын
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 жыл бұрын
Legit happens to me
@soumojitchowdhury151
@soumojitchowdhury151 3 жыл бұрын
@@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 3 жыл бұрын
you got me b*tch!
@va9if
@va9if 3 жыл бұрын
I thought he wasn't serious when he said "calculate π"
@pablogarin
@pablogarin 4 жыл бұрын
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
@marceloaugusto7830
@marceloaugusto7830 4 жыл бұрын
or just use google....
@ShibayanMondal
@ShibayanMondal 3 жыл бұрын
2:58 The greatest sense of humour I have ever seen!
@jepoyburner
@jepoyburner 3 жыл бұрын
This is the classic Monte Carlo introduction problem. Ptsd to my thesis days.
@yogendraadhikari4275
@yogendraadhikari4275 3 жыл бұрын
If someone asks me this kind of question, I would just walk away...
@jhay_vine5083
@jhay_vine5083 3 жыл бұрын
Facts bro 😂😂😂
@faizanali193
@faizanali193 3 жыл бұрын
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 3 жыл бұрын
@@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.
@Dew_-km7gr
@Dew_-km7gr 4 жыл бұрын
3:01 my math teacher every time I ask him something 😂😔👌
@pukhatozhimo
@pukhatozhimo 3 жыл бұрын
Lol, I'm a math teacher. 😂😂
@odikuhschrank7936
@odikuhschrank7936 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.
@amaizel
@amaizel 3 жыл бұрын
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!
@Hyttelus
@Hyttelus 3 жыл бұрын
This was literally one of the exam question in a programming and microcontroller course I took this semester.
@jdmaine51084
@jdmaine51084 4 жыл бұрын
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.
@Supertweeb
@Supertweeb 3 жыл бұрын
5:32 that googling google to go to Google killed me 🤣🤣🤣🤣
@jamiejackson2144
@jamiejackson2144 4 жыл бұрын
Instead of using another variable incrementing for total points, you can directly use "n" which came as input argument.
@ellmango
@ellmango 2 жыл бұрын
lmao
@javand86
@javand86 2 жыл бұрын
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!
@braer240
@braer240 3 жыл бұрын
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
@Oscarrudnas
@Oscarrudnas 4 жыл бұрын
I was going to comment: I could learn this all day if you would teach it. And then joma academia. Nice thanks
@stevenspearman5697
@stevenspearman5697 4 жыл бұрын
5:27 - You went to google.com to google google and clicked on the first google link to take you to google. BIG BRAIN!
@anubhavagrawal3963
@anubhavagrawal3963 4 жыл бұрын
Teaching recursion for free. 😌
@abeecee
@abeecee 4 жыл бұрын
More of these pls I love them, also the coding explanations really help beginners. Love u joma
@frankpujo8073
@frankpujo8073 4 жыл бұрын
2:52 don't mind me, just wanted the golden moment of the video to replay
@luchodasavage
@luchodasavage 3 жыл бұрын
I don't even like math, but can't stop watching videos of this dude
@Glendragon
@Glendragon 3 жыл бұрын
first number: 3.6 (0,46 away) second number: 2.92 (0,22 away) Joma: "that is not more accurate"
@francoisa3231
@francoisa3231 4 жыл бұрын
You can actually just divide by n
@jomakaze
@jomakaze 4 жыл бұрын
Yea oops
@3lietechhack646
@3lietechhack646 4 жыл бұрын
How? Could you please explain?
@francoisa3231
@francoisa3231 4 жыл бұрын
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 жыл бұрын
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 жыл бұрын
It doesn't matter, I'm not going to write any of these calcs for my applications anyways
@lexus7154
@lexus7154 3 жыл бұрын
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.
@wristocrat
@wristocrat 2 жыл бұрын
Easily the funnest programming tutorial I've ever seen, great information too
@bogdns
@bogdns 4 жыл бұрын
num_point_total is really useful( “n” is useless)
@jeremyshaw1
@jeremyshaw1 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.
@angry_moose94
@angry_moose94 3 жыл бұрын
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.
@kxmode
@kxmode 4 жыл бұрын
"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." _Question 1A:_ var a = []; function Random(min, max, cap) { for (var i = 0; i < cap; i++) { var v = (Math.random() * (max - min) + min).toString(); v = v.substring(0,4); v = parseFloat(v); a.push(v); } return a; } // returns 50 floating point values between 0 and 1 in an array console.log(Random(0, 1, 50)); Example output: [0.95, 0.76, 0.7, 0.48, 0.89, 0.75, 0.26, 0.63, 0.28, 0.91, 0.48, 0.36, 0.56, 0.29, 0.23, 0.64, 0.5, 0.73, 0.2, 0.87, 0.81, 0.02, 0.97, 0.91, 0.4, 0.77, 0.24, 0.71, 0.62, 0.08, 0.89, 0.93, 0.94, 0.8, 0.49, 0.84, 0.91, 0.26, 0.68, 0.23, 0.98, 0.55, 0.58, 0.77, 0.01, 0.95, 0.15, 0.54, 0.96, 0.11] _Question 1B:_ 3.14159265359
@Oleg-mv6cx
@Oleg-mv6cx 2 жыл бұрын
import math n = int(input("Input: ")) pi=0 for i in range(n): if i!=0: pi += 1/float(i*i) pi = math.sqrt(6*pi) print("Output: "+str(pi))
@omegacon4
@omegacon4 4 жыл бұрын
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.
@tarunpatel8168
@tarunpatel8168 3 жыл бұрын
Joma you are amazing, I laughed hard at 5:30 😂😂 Amazing content too
@OpannapO
@OpannapO 3 жыл бұрын
agree with u 😂
@nikolatesla399
@nikolatesla399 Жыл бұрын
😂😂
@bryanfeliciano4102
@bryanfeliciano4102 4 жыл бұрын
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 жыл бұрын
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 жыл бұрын
Lmaoo
@DrRAZI99
@DrRAZI99 3 жыл бұрын
Lol
@bryanfeliciano4102
@bryanfeliciano4102 3 жыл бұрын
@@DrRAZI99 glad that made you giggle 😂
@nyb_ok
@nyb_ok 3 жыл бұрын
Its ok. Noone can know everything.
@soumojitchowdhury151
@soumojitchowdhury151 3 жыл бұрын
That logic of thinking with the graph is where the main clue is... Awesome idea
@krisztianszabo3588
@krisztianszabo3588 3 жыл бұрын
import random def calculate_pi(n): return 4*(sum([1 for _ in range(n) if random.uniform(0,1)**2+random.uniform(0,1)**2
@calosth
@calosth 4 жыл бұрын
All the knowledge inside this piece of humor, I had to stop and laugh for every joke. Really well done 👏🏼
@ameysawant2301
@ameysawant2301 4 жыл бұрын
Why no one is talking about how funny at the same time educational his videos are😂😂😂😂😂😂😂😂😂 !!!! You are doing a great job JOMA ✨✨✨✨🔥🔥🔥🔥🔥
@firepro20
@firepro20 4 жыл бұрын
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.
@yoonhero3701
@yoonhero3701 2 жыл бұрын
Joma, How about this way? import math def getDistance(x, y): return math.sqrt(x**2 + y**2) def getPos(x, y, r, total): return r/total * x, r/total*y def getPI(n): radius = 1 num = 0 for x in range(n): for y in range(n): posX, posY = getPos(x, y, radius, n) if getDistance(posX, posY)
@manucanedo8039
@manucanedo8039 3 жыл бұрын
Did it in a different way. Calculated points in a hemisphere centred at 0.5 and with those calculated half a perimeter. With the perimeter calculated PI. Get's closer the more points you generate. Here's the C++ for it: #include #include #include #include #include constexpr double RADIUS = 0.5; constexpr double CENTRE = 0.5; constexpr double ITERS = 1000000; constexpr double get_abs(const double x, const double y) { return std::sqrt(x * x + y * y); } constexpr double get_y(const double x) { constexpr double sqr_H = RADIUS * RADIUS; return std::sqrt(sqr_H - x * x); } double rand_double() { return static_cast(rand()) / static_cast(RAND_MAX); } int main() { srand(static_cast(time(0))); std::map data; for (int i = 0; i < ITERS; ++i) { double x = rand_double() - CENTRE; data.emplace(x, get_y(x)); } auto prev_it = data.cbegin(); auto it = ++data.cbegin(); long double circle_len = 0.0; for (; it != data.cend(); ++it) { circle_len += get_abs(it->first - prev_it->first, it->second - prev_it->second); prev_it = it; } printf("Calculated PI is: %Lf", circle_len / RADIUS); return 0; }
@mamertvonn
@mamertvonn 4 жыл бұрын
5:26 dis cures my depression...
@pmoe7
@pmoe7 4 жыл бұрын
I genuinely died when he searched up the area of the circle 😂😂😂
@saisagar5639
@saisagar5639 4 жыл бұрын
Yes
@thelastilluminati6959
@thelastilluminati6959 4 жыл бұрын
why are you still alive then
@legohexman2858
@legohexman2858 3 жыл бұрын
@@thelastilluminati6959 because he was revived by the funny
@EmissaryOfSmeagol
@EmissaryOfSmeagol 4 жыл бұрын
pdf of given funciton: p(x)=1, x in [0,1], 0 otherwise. integral(0,1) 4*arctan(p(x)) dx = pi
@alexchepilko4298
@alexchepilko4298 4 жыл бұрын
My first though was gauss integral
@videostop7564
@videostop7564 4 жыл бұрын
I concur
@MoritzWallis
@MoritzWallis 4 жыл бұрын
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.
@TrueZenquiorra
@TrueZenquiorra 4 жыл бұрын
Hey Joma! I really loved this content, gonna share with my friends to blow their minds.
@muhammadwasi5460
@muhammadwasi5460 4 жыл бұрын
Dude this man is my favourite...except he shows up on my interview day lamo..i'm dead...
@PriyanshGupta2906
@PriyanshGupta2906 4 жыл бұрын
This is called the Montecarlo simulation
@jomardomingos7886
@jomardomingos7886 3 жыл бұрын
Your sense of humor is great!
@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
@Martyballin
@Martyballin 4 жыл бұрын
These questions are good for boosting the ego of the interviewer, nothing more.
@jeremyshaw1
@jeremyshaw1 4 жыл бұрын
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 жыл бұрын
It's a classical problem. making an approximation of pi using proba. here we used the monte carlo method.
@ignaciosavi7739
@ignaciosavi7739 4 жыл бұрын
@@jeremyshaw1 i solved it in 5 mins.
@daniele4839
@daniele4839 4 жыл бұрын
@@ignaciosavi7739 I solved it in 2
@ignaciosavi7739
@ignaciosavi7739 4 жыл бұрын
@@daniele4839 great job!
@calvintran6544
@calvintran6544 3 жыл бұрын
6:08 when he typed in x^2 first before x**2 😂 gets me every time
@linx3519
@linx3519 3 жыл бұрын
Joma: .. the area of the circle? oh you didn't know? 3:04 😂😂 love this one
@l.meyers3348
@l.meyers3348 3 жыл бұрын
“Fuckin idiot”…both makes me laugh and cry. Genius, just genius!
@mionszu
@mionszu 3 жыл бұрын
Wow, I remember that. I had it once in my high school classes. Good to know it can be an interview question
@josephajibodu2377
@josephajibodu2377 3 жыл бұрын
I thought I've seen it all at 3:04, I never knew there was more at 5:30. 😂😂
@callforjhed
@callforjhed 4 жыл бұрын
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!
@saimyintmyat9373
@saimyintmyat9373 4 жыл бұрын
Pork 😂😂😂😂
@jeps7688
@jeps7688 4 жыл бұрын
5:29 thats me having trust issue googling google.
@vejymonsta3006
@vejymonsta3006 4 жыл бұрын
In chrome
@futbolcolombiano320
@futbolcolombiano320 4 жыл бұрын
I didn't get why he did that. Would you let me know?
@michaeldang8189
@michaeldang8189 4 жыл бұрын
That is a recursive algorithm
@Saladmints
@Saladmints 4 жыл бұрын
Based off of just drawing the quadrant with all the dots: you find the proportion of points where x^2 + y^2
@stevesmith9447
@stevesmith9447 4 жыл бұрын
Tell your interviewer you'll compete against them. They write their version, you write yours. If yours is faster, you get double your salary the first year. If it's slower, you get one tenth your salary the first year. When they accept, skip the RNG. Use a uniform field. You still take a resolution, N, and you take the same approach. But for starters, you work only in the +x,+y quarter of the unit circle (the area ratio is the same). There are N^2 points in the square. How many are in the circle? Start with the point D = (sqrt(0.5), sqrt(0.5)), which is on x=y and also on the unit circle. It reveals a square of size 0.5*N^2; those points are all within the circle. That's O(1). Now we can make two triangles by drawing lines from D to (1,0) and (0,1). The area of these is also within the circle; their combined area is sqrt(0.5)*(1-sqrt(0.5))*N^2. Again, O(1). From there, we just need to iterate from the hypotenuse of the two triangles out to the circle edge in order to compute the number of points in each column that are within the circle. We only need to do it once and then double it because they're symmetrical. We can search the upper triangle by rows and binary search over N to the edge for each row. We want to search by rows because 1-sqrt(0.5) is less than sqrt(0.5), so we're minimizing the iteration. 90% of the points are computed in O(1). The remaining 10% are computed in approximately (N log N) / 4 operations. log(1M)=20 (about). 5M*0.1 = 0.5M. Twice as fast as the O(N) RNG algorithm.
@hypno5690
@hypno5690 2 жыл бұрын
And then they say, no thanks just complete the question please. I bet you win so many shower arguments. Like using the rng is the whole point of the challenge lmao.
@bluehornet6752
@bluehornet6752 4 жыл бұрын
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.
@carlavntr
@carlavntr 4 жыл бұрын
What kind of program do you use to draw like that? Thank you you're awesome
@nilanjanmukhopadhyay8369
@nilanjanmukhopadhyay8369 3 жыл бұрын
Solution with time and space complexity O(1) When I have heard the problem I started to think about it in a different way than the solution he showed. Later, I attempted to find the solution in my way nonetheless. I have come up with the solution with the time and space complexity of O(1). However, I doubt if it would be considered as a solution. The algorithm not only will solve for any number at the range [0, 1] but also will work for literally any number in the range of (-infinity, infinity). The process is as follows, *f(x) = cos(x)* This function will spit out real numbers in the range of [-1, 1]. Let's just play with the function a bit so that it spits output in the range [0, 1]. _f(x) = 0.5 * cos(x) + 0.5 // domain = (-infinity, infinity), range = [0, 1]_ Now, whenever the output will be 0 the input will be pi. (I know for infinitely many inputs it will output zero but the range of the arccosine function is [0, pi], so no issue in this particular case). Using the randomly generated number the function can be modified in a way such that irrespective of the random number the *x* will always be *pi*. let the_random_number = rand _f(x) = 0.5 * cos(x) + 0.5 + rand // thus if the output of the function is _*_rand_*_ then _*_x_*_ will be _*_pi_* Here on we can solve for *x* _rand = 0.5 * cos(x) + 0.5 + rand_ or, cos(x) = (rand - rand) - 0.5 / 0.5 _or, x = arccos((rand - rand) - 0.5 / 0.5)_ Thus, the *x* will always be *pi* regardless of what actually the *rand* is. However, it turns out that the RHS of the equation always becomes -1. The equation exactly the same as saying x = arccos(-1) which is always pi. Given the process can anybody please argue why or why not it will be accepted as a solution? *#python** implementation of the program* *import math, random* *def func():* *rand = random.uniform(0,1)* *return math.acos((rand - rand) - 0.5 / 0.5)*
@TNothingFree
@TNothingFree 3 жыл бұрын
Very neat question, The moment you said PI I said to myself "Probably calculating distances" which I was close to >< Circles and Algebra are one way to challenge someone to inspect how their thinking process works.
@ChristopherLandicho-uc5vp
@ChristopherLandicho-uc5vp Жыл бұрын
I tried implementing this in C#, and so far, it's been working fine. This is my code : using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Calculate_Pi { class Program { static void Main(string[] args) { Console.WriteLine("Enter the number of points:"); int numPoints = int.Parse(Console.ReadLine()); double pi = EstimatePi(numPoints); Console.WriteLine($"Estimated value of pi: {pi}"); Console.WriteLine("Press Enter to exit..."); while (Console.ReadKey().Key != ConsoleKey.Enter) { // Keep looping until the Enter key is pressed } } static double EstimatePi(int numPoints) { Random random = new Random(); int pointsInsideCircle = 0; int pointsInsideSquare = 0; for (int i = 0; i < numPoints; i++) { double x = random.NextDouble(); double y = random.NextDouble(); double distance = x * x + y * y; if (distance
@ariadnamartinleon4217
@ariadnamartinleon4217 4 жыл бұрын
please, do more videos like this one, with actual coding, it helps a lot!
@sohumsharma2892
@sohumsharma2892 3 жыл бұрын
I was able to solve after you drew the graph
@hashimalsmael3396
@hashimalsmael3396 3 жыл бұрын
3:04 I see what you did there I nearly died laughing LMFAO
@osmiforcentrio7866
@osmiforcentrio7866 4 жыл бұрын
that's like genius. Especially if the interviewers are staring at you ........judging you
@Whiteleon13
@Whiteleon13 3 жыл бұрын
Bro your humor is real epic love it, not even cringe
@franciscoramirez-lt3zc
@franciscoramirez-lt3zc 3 жыл бұрын
Took me a minute to wrap my head around this. Here it is for the rest of the smewth brains (I think): Area of a Circle: Pi x r² Pythagorean Theorem: √ (a² + b²) *Note:* A circle has 4 quadrants. Since our numbers are in the range 0-1, we only care about the 1st quadrant (all other quadrants contain a negative in either the x or y-axis). *Process:* If we scribe a square around a circle it will contain the circle's maximum x and y values (1, 1). By taking the ratio (points in circle/points outside of the circle) we can find a number that tends towards pi. So we use Pythagorean to find the location of the point and to populate some of that area in the square (in or outside the circle.)*Since this is only for one quadrant the number will _actually_ be one-quarter of pie.* The more iterations we allow, the higher accuracy we will find (more area populated in the square).
@tristunalekzander5608
@tristunalekzander5608 3 жыл бұрын
The question doesn't even say you need to use the random function to solve it.
@justinchun5975
@justinchun5975 4 жыл бұрын
Literally no one: Joma: GOOGLES GOOGLE
@eformance
@eformance 3 жыл бұрын
I can see this as being a useful way to test RNG data sources, the closer they get to pi, the more random they are.
@dgory
@dgory 3 жыл бұрын
import numpy as np def estimate_pi(n): return (4*np.mean( np.linalg.norm( np.random.rand(n, 2), axis=1) < 1))
@UmarMash
@UmarMash 4 жыл бұрын
3:04 i lit laughed so hard... after all the bragging....lol
@toaderadrian3146
@toaderadrian3146 4 жыл бұрын
2:58 ,my brain after exams
@SurferFlash
@SurferFlash 4 жыл бұрын
My favorite interview question to ask for engineering positions: - How many tennis balls fit in an airplane?
@technologyondemand4538
@technologyondemand4538 4 жыл бұрын
>asks siri in interview
@bilbobaggins7075
@bilbobaggins7075 4 жыл бұрын
At least 1
@Amsoniac
@Amsoniac 4 жыл бұрын
Wait now I want to know the answer. Would it be something like B = ball radius A = airplane volume X = number of balls So: A = (Br^2) * X Or some other function, or are you looking to see if they react a certain way. I know that function is wrong but bathroom breaks only last so long
@Borg8
@Borg8 2 жыл бұрын
double sum = 0; double c = 0; Random r = new Random(); for (;;) { double x = r.nextDouble(); ++c; sum += Math.sqrt(1 - x * x); // you don't need to choose random y, it will be more accurate to compute it from given x. System.out.println("pi~" + sum * 4 / c); }
@NStripleseven
@NStripleseven 4 жыл бұрын
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.
How I Spend My $250K Software Engineer Income
15:58
Joma Tech
Рет қаралды 3 МЛН
10 years of coding in 13 minutes
13:28
Joma Tech
Рет қаралды 4,9 МЛН
快乐总是短暂的!😂 #搞笑夫妻 #爱美食爱生活 #搞笑达人
00:14
朱大帅and依美姐
Рет қаралды 11 МЛН
3 Types of Data Science Interview Questions
8:09
Joma Tech
Рет қаралды 650 М.
How Many ERRORS Can You Fit in a Video?!
20:40
ElectroBOOM
Рет қаралды 3,5 МЛН
I Got Rejected By A 22-Year Old CEO
7:00
Joma Tech
Рет қаралды 4 МЛН
why you NEED math for programming
5:03
Joma Tech
Рет қаралды 9 МЛН
Google Coding Interview With A High School Student
57:24
Clément Mihailescu
Рет қаралды 4,2 МЛН
me trying to flirt with my crush for 12 minutes straight
14:44
Joma in NYC
Рет қаралды 2,2 МЛН
How to Make it Through Calculus (Neil deGrasse Tyson)
3:38
Jonathan Arrington
Рет қаралды 1,6 МЛН
5 Signs of an Inexperienced Self-Taught Developer (and how to fix)
8:40