/mathecarlo

Bruteforcing to derive π

Primary LanguageJavaScriptMIT LicenseMIT

mathecarlo

Bruteforcing to derive π

image

How?

  • Creating a canvas - with a square, and a circle that fully fills the square
  • Plotting a point with randomly generated co-ordinates.
  • Measuring (through the pythagoras theorem) if the point falls within the circle or not.
  • Getting the ratio of points in the circle, to those generated in total
  • Multiplying the ratio by 4 - to get π