A Random Way to Calculate Pi #piday #shorts

preview_player
Показать описание
Happy Pi Day!

Animated with:
Рекомендации по теме
Комментарии
Автор

A number of people have asked to see the code for this approximation, so here's an implementation in Python:


from random import random

total = 3141
count = 0

for i in range(total):
x = random()
y = random()
if x*x + y*y <= 1:
count += 1

print("Pi is approximately " + str(4 * count / total))

nubdotdev
Автор

i am completely amazed at the fact that this is not extremely popular considering how clean this editing and explanation is

natedor
Автор

“A bit over 3, 000, ” you say. That wouldn’t be 3, 141 by chance?

joebykaeby
Автор

"A bit over 3000" I see what you've done here

rjms
Автор

That's great. One thing I find interesting is how points are meant to be dimension less, yet we use them to approximate area.

abdullahaddous
Автор

I may be a lil bit of a geek. But I still do this from time to time just for fun. Especially on Pi day even though I am a medical student now my passion for mathematics has never faded😂. Subscribed🙂🙂🙂

mrK
Автор

you can also get rid of a random:
count = 0
rad = 1000
total = (rad*2)**2
for x in range(rad*2):
for y in range(rad*2):
if (x-rad)**2 + (y-rad)**2 <= rad**2:
count += 1
print(4*count/total)

corbi
Автор

You did a great job Justin!
It's always cool to learn something random here and there, I already can see myself telling this to a random friend at a party lmao.

panzerkampfwagentigerausfb
Автор

Just found your channel and subscribed, I hope you keep making stuff like this from time to time!

revenevan
Автор

How is this channel and the video not that popular already?

drenz
Автор

POV: you were trying to find some anime videos but you get this in your Recommended

Lore_play
Автор

We actually coded this for CS class a few years back. Good times

pafnutiytheartist
Автор

Just in case if anyone want the code for this algorithm, it's written in javaScript so you can run the code in browser console .

var n =
var ins = 0, outs = 0;
for(var i = 0; i < n ;i++){
var x = Math.random();
var y = Math.random();
var z = Math.sqrt(x*x + y*y);
if(z <= 1) ins++; outs++;
}
var est_pi = (4 * ins)/outs;
console.log(est_pi);

You can increase value of n for more precision. Let me know for any correction or suggestions.HFHF.

mlembleh
Автор

Props to those people who actually counted the dots.

randomguyeverywhere
Автор

commenting for the algorithm, this is some amazing stuff!

yuma
Автор

This is how schools should teach maths. They have to visualize it and explain how a certain formula is made.

frankineskinecense
Автор

THIS kind of stuff should be in my school on Pi Day

jurekis
Автор

It would be also very interesting to see this method compared to a method using evenly spaced dots and comparing them! This would also raise the question at what number of points one is more exact than the other.

janni
Автор

Well umm you could this by just integraring on a quarter unit circle and equate it with binomial expanded form of the same integral and then you could calculate pie on any order you want (I know what he did in the video was kind of integration only )

chayanaggarwal
Автор

I was with you for like 5 seconds. Then my brain liquefied and ran out of my nose

davidtatum