Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBaum123 authored Apr 19, 2024
1 parent f6c9858 commit 296eee1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Main {
public static void main(String[] args) {
int ammountOfPoints = (args.length > 0) ? Integer.parseInt(args[0]) : 1000000000;
int timesToLog = (ammountOfPoints < 100) ? ammountOfPoints : 100;
int circleRadius = 1;
int pointsTotal = 0;
int pointsInCircle = 0;
for(int i = 0; i < ammountOfPoints; i++) {
double pointX = Math.random() * circleRadius * 2 - circleRadius;
double pointY = Math.random() * circleRadius * 2 - circleRadius;
double distanceFromCenter = Math.sqrt(pointX * pointX + pointY * pointY);
if(distanceFromCenter < circleRadius) {
pointsInCircle++;
}
pointsTotal++;
if (pointsTotal % (ammountOfPoints / timesToLog) == 0) {
double estPi = 4 * ((double) pointsInCircle / (double) pointsTotal);
System.out.println("Estimation of PI using " + pointsTotal + " points: " + estPi);
System.out.printf("Off by: %.10f\n", (estPi - Math.PI));
System.out.println((int)((float)pointsTotal / (float)ammountOfPoints * 100f) + "% done");
}
}
}
}
2 changes: 2 additions & 0 deletions manifest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Manifest-Version: 1.0
Main-Class: Main

0 comments on commit 296eee1

Please sign in to comment.