Initial commit
This commit is contained in:
12
Python/code_cycle.py
Normal file
12
Python/code_cycle.py
Normal file
@@ -0,0 +1,12 @@
|
||||
total_attempts = 256*256*256
|
||||
successful_attempts = 0
|
||||
|
||||
for a in range(0, 256):
|
||||
for b in range(0, 256):
|
||||
for c in range(0, 256):
|
||||
if a + b + c > 300:
|
||||
successful_attempts += 1
|
||||
|
||||
print(f"Iterations: {total_attempts}")
|
||||
print(f"Valid sums: {successful_attempts}")
|
||||
print(f"Probability: {successful_attempts / total_attempts}")
|
||||
17
Python/code_unoptimised.py
Normal file
17
Python/code_unoptimised.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from random import randint
|
||||
|
||||
total_attempts = 15_000_000
|
||||
successful_attempts = 0
|
||||
|
||||
for i in range(0, total_attempts):
|
||||
a = randint(0, 256)
|
||||
b = randint(0, 256)
|
||||
c = randint(0, 256)
|
||||
|
||||
if a + b + c > 300:
|
||||
successful_attempts += 1
|
||||
|
||||
|
||||
print(f"Iterations: {total_attempts}")
|
||||
print(f"Valid sums: {successful_attempts}")
|
||||
print(f"Probability: {successful_attempts / total_attempts}")
|
||||
Reference in New Issue
Block a user