Today is 3/14 (In America, sorry everyone [?] else). This is Pi day.
I present a "fun" program that kinda calculates an approximation for Pi. It uses a Monte Carlo method, which isn't exact, but can get close over time. Being in PICO-8, it can't run for very long before running out of memory, but it still kinda works.
For more on Monte Carlo methods, I adapted mine from this Wikipedia page
fun fact: If you edit the program to have the line srand(314)
toward the top, it will get 3.1416, the closest you can get to Pi with only 4 decimal places (It would be 3.1415, but the next digit is 9, so rounded, it's closer).
P#127147 2023-03-14 21:59


Nice. We did this same thing as an exercise at the beginning of my computational physics course in my undergrad.
P#127349 2023-03-20 03:53
[Please log in to post a comment]