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

P#127147 2023-03-14 21:59

Happy Pi day :)

P#127148 2023-03-14 22:11

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]

Follow Lexaloffle:          
Generated 2024-03-29 14:51:37 | 0.011s | Q:20