Share your repls and programming experiences

← Back to all posts
Happy Pi Day!
h
Nayoar (561)

Hello everyone!

Some people on the Replit Discord pointed out to me that it was Pi Day, but I hadn't made anything special. So, I came up with this idea - a program which calculates pi using random numbers and includes a nice visual of what it does!

Here's how it works:
Consider the square to have a side length of 2, and an area of 4. The circle has a radius of 1, and an area of π. Each point is chosen at a random position within the square. The chances of a point falling inside the circle are π/4, so to find the value of π, simply multiply the fraction of points which are inside the circle by 4.

I hope you enjoy - let me know the values for pi that you calculate with this!

Thanks to @Spotandjake for helping me fix a bug regarding canvas sizing.

Edit: I left it running overnight...

Comments
hotnewtop
ch1ck3n (1621)

Chuck Norris's PIN is the last 4 digits of PI.

tussiez (1518)

@ch1ck3n Ah yes, I figured that out ages ago. It's #### ARR ROBLOX CENSOR!

ch1ck3n (1621)

@tussiez #####################

tussiez (1518)

@###### ##########################################

tussiez (1518)

@220723j Wrong! #######################

tussiez (1518)

@######## #### ####### ################ ################# ###############

220723j (4)

@tussiez 3.14159265358979323?

AJDevelopment (137)

@####### ## ### ###### ##### #### ####

Hyderite (1)

@220723j 3.14159265358979323846 (i recited it lol)

FuturisticIdiot (1)

@Hyderite 3.14159265358979323846264338327950

Coder100 (17038)

cookie stfu and just updoot it

ok

Spotandjake (28)

@Coder100 lmao I really wish there was a downdoot just for fun lmao

Spotandjake (28)

@potatojs it could go very bad I think it should be an option though like you can enable it for your posts

doineednumbers (26)

It appears that the equation you used is 4 inCircle / total, shouldn't it be 4 (inCircle / total) or am I missing something?

Nayoar (561)

@doineednumbers those two expressions are the same :)

Whippingdot (570)

sooo many miniature pies

that is what the program is...right?

Bookie0 (5974)

I am assisting to the creation of the universe!!

ToonRoMiner (0)

It looks like a color-blind test thing lol

BellaKou (0)

What?? is?? that??

Andy_4sberg (50)

lol! I just randomly liked the bottom comment. LOL

BotProgrammer (9)

I found the article you got this info from!

Nayoar (561)

@BotProgrammer uh, I didn't get this info from an article. It's a very basic method and I'm sure there are hundreds if not thousands of articles on it.

KrazyOrange (27)

omg the value of pi is 3.15! 0_0

KrazyOrange (27)

Wow this is really smart!

Nayoar (561)

@KrazyOrange thanks, though I didn't come up with the idea myself. I've seen many different implementations of it in the past

TheC0derGirl (218)

lol funny that im commenting from a raspberry pi XD

kewl repl!

Gh0stHack3r (57)

It would take one year MILLIONS OF YEARS for It to actually reach
the quintillion digits!!

Nayoar (561)

@Gh0stHack3r I doubt it would ever reach that with randomness.

oignons (237)

i'm a day late but this is actually a really cool way of doing it, take my upvote minks minx

Nayoar (561)

@oignons thanks (dw I'm now even later)

LegendaryWolf (694)

WHO HAD A PERFECT CIRCLE?

Nayoar (561)

@LegendaryWolf me, when I left it running overnight

IcynDevz (764)

The first few digits of pi: 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679...

RayhanADev (1940)

liking this on pi day at 3:14:

big brain moments 2021

potatojs (844)

btw today is einstein's birthday :D

Spotandjake (28)

Also minx lol you don't need to thank me for fixing it lol I literally added two lines lmao thanks anyways but not needed really lol.

JDOG787 (431)

Dang, it's already been a year...

Spotandjake (28)

@minx28 it is interesting I wish you could make it faster lol though maybe a pre calculated map lol or something.

potatojs (844)

@Spotandjake no he can just add multipule points per frame!
something like that

Spotandjake (28)

@potatojs he could for sure lol but eventually it gets slow a precomputed map is good for speed lol

potatojs (844)

lol there is a much more beautiful and unexpected way which is:
if you take 2 random integers, the probability that they are co factor (share a gcd bigger than 1) is 6/PI²
isn't that absolutely gorgeous!

Nayoar (561)

@potatojs yes, I have heard of that. It is very nice, but harder to implement, and also doesn't have an obvious visual representation like this does.

potatojs (844)

@minx28 ah ok but the method you used is still cool

Spotandjake (28)

@k9chelsea2 I don't know how to rename lol

potatojs (844)

@Spotandjake ehhh why? is he a teacher or something idk

Spotandjake (28)

@potatojs lol it is a joke from the discord sort of lol

Kookiez (386)

@k9chelsea2 maths is british english, math is american english

Nayoar (561)

@Kookiez
"british english" --> "correct english"
"american english" --> "english with mistakes"
(thanks for the updoot though)

potatojs (844)

@k9chelsea2 wdym i know engrish very well and he's right!

Spotandjake (28)

@potatojs minx I's brit lol I canadian so it is really just a different way of speaking lol I would argue both are correct lol and maths is more correct lol and I know engrish too lol it is my favourite language lmao

potatojs (844)

@Spotandjake haha ok, but maths is right
you said lol way too many times are you okay?

Spotandjake (28)

@potatojs I like to laugh I see know problem in that I think laughing is good to be honest.

FlaminHotValdez (441)

@minx28

"british english" --> "correct for british people"
"american english" --> "correct for american people"

Look no one is going to know what a biscuit is in the USA. Heck the only reason I know what it is is because I utilize Google.

Spotandjake (28)

@FlaminHotValdez i would argue that british terms with the internet have made there way around lol, just less common. i would argue that maths is more correct tbh but I would argue that it should be linguistics and sciences as well at the end of the day lol I say math because it is more familiar and I am talking about the subject as a whole not the plural of rules that it defines lol.

Kookiez (386)

@FlaminHotValdez a biscuit is a breakfast food. in britain, they're cookies, which doesn't make sense to me because biscuits are nothing like cookies. Wait, now i'm confused with myself

Spotandjake (28)

@Kookiez lol it makes a lot of sense i just think you consider a cookie to be only a sweet lol when it is really just a form of pastry lol.