Initial commit

This commit is contained in:
2024-03-11 12:43:52 +02:00
parent 0cc291f3d8
commit a57340adb7
55 changed files with 2961 additions and 1 deletions

6
Java/Makefile Normal file
View File

@@ -0,0 +1,6 @@
compile:
javac code_cycle.java
javac code_unoptimised.java
clean:
rm *.class

20
Java/code_cycle.java Normal file
View File

@@ -0,0 +1,20 @@
public class code_cycle {
public static void main(String[] args) {
int total_attempts = 256*256*256;
int successful_attempts = 0;
for (int a = 0; a < 256; a++) {
for (int b = 0; b < 256; b++) {
for (int c = 0; c < 256; c++) {
if (a + b + c > 300) {
successful_attempts++;
}
}
}
}
System.out.println("Iterations: " + total_attempts);
System.out.println("Valid sums: " + successful_attempts);
System.out.println("Probability: " + (float) successful_attempts / total_attempts);
}
}

View File

@@ -0,0 +1,22 @@
import java.util.concurrent.ThreadLocalRandom;
public class code_unoptimised {
public static void main(String[] args) {
int total_attempts = 15_000_000;
int successful_attempts = 0;
for (int i = 0; i < total_attempts; i++) {
int a = ThreadLocalRandom.current().nextInt(256);
int b = ThreadLocalRandom.current().nextInt(256);
int c = ThreadLocalRandom.current().nextInt(256);
if (a + b + c > 300) {
successful_attempts++;
}
}
System.out.println("Iterations: " + total_attempts);
System.out.println("Valid sums: " + successful_attempts);
System.out.println("Probability: " + (float) successful_attempts / total_attempts);
}
}