Log In  


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

Cart #happypiday-0 | 2023-03-14 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
5

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).

5


Happy Pi day :)


Nice. We did this same thing as an exercise at the beginning of my computational physics course in my undergrad.



[Please log in to post a comment]