/adaptive.py Secret
Created
September 28, 2023 16:40
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random as r | |
from openpyxl import Workbook | |
def xq_only(initial): | |
N = initial | |
new_prod = 0 | |
while N >= 3: | |
if r.random() < 0.25: | |
N += 1 | |
new_prod += 1 | |
N -= 3 | |
return new_prod*3 + N | |
def eula_only(initial): | |
N = initial | |
new_prod = 0 | |
while N >= 3: | |
if r.random() < 0.10: | |
new_prod += 1 | |
new_prod += 1 | |
N -= 3 | |
return new_prod*3 + N | |
def combined(initial): | |
N = initial | |
new_prod = 0 | |
while N >= 3: | |
rem = N % 3 | |
if rem == 2 or (rem == 1 and N >= 10): | |
if r.random() < 0.25: | |
N += 1 | |
else: | |
if r.random() < 0.10: | |
new_prod += 1 | |
new_prod += 1 | |
N -= 3 | |
return new_prod*3 + N | |
initial = 9000 | |
final = initial + 999 | |
n = initial//3 | |
limit = final//3 | |
iterations = 5000 | |
better_count = 0 | |
wb = Workbook() | |
ws = wb.active | |
while n <= limit: | |
N = 3*n + 1 | |
eula = 0 | |
xq = 0 | |
both = 0 | |
for _ in range(iterations): | |
eula += eula_only(N) | |
xq += xq_only(N) | |
both += combined(N) | |
eula /= iterations | |
xq /= iterations | |
both /= iterations | |
better = both >= eula and both >= xq | |
if better: better_count += 1 | |
print(f'N = {N} BETTER = {better}; ({xq/xq}, {eula/xq}, {both/xq}); ({xq}, {eula}, {both})') | |
ws.append([N, better, xq/xq, eula/xq, both/xq, xq, eula, both]) | |
n += 1 | |
print(f'{better_count}/{final//3 - initial//3 + 1}') | |
print(better_count/(final//3 - initial//3 + 1)) | |
wb.save('1mod3.xlsx') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random as r | |
from openpyxl import Workbook | |
def xq_only(initial): | |
N = initial | |
new_prod = 0 | |
while N >= 3: | |
if r.random() < 0.25: | |
N += 1 | |
new_prod += 1 | |
N -= 3 | |
return new_prod*3 + N | |
def eula_only(initial): | |
N = initial | |
new_prod = 0 | |
while N >= 3: | |
if r.random() < 0.10: | |
new_prod += 1 | |
new_prod += 1 | |
N -= 3 | |
return new_prod*3 + N | |
def combined(initial): | |
N = initial | |
new_prod = 0 | |
go_for_25 = (N % 3 == 2) or (N % 3 == 1 and N >= 10) | |
while N >= 3: | |
if go_for_25 and N % 3 != 0: | |
if r.random() < 0.25: | |
N += 1 | |
else: | |
if r.random() < 0.10: | |
new_prod += 1 | |
new_prod += 1 | |
N -= 3 | |
return new_prod*3 + N | |
initial = 9000 | |
final = initial + 999 | |
n = initial//3 | |
limit = final//3 | |
iterations = 5000 | |
better_count = 0 | |
wb = Workbook() | |
ws = wb.active | |
while n <= limit: | |
N = 3*n + 1 | |
eula = 0 | |
xq = 0 | |
both = 0 | |
for _ in range(iterations): | |
eula += eula_only(N) | |
xq += xq_only(N) | |
both += combined(N) | |
eula /= iterations | |
xq /= iterations | |
both /= iterations | |
better = both >= eula and both >= xq | |
if better: better_count += 1 | |
print(f'N = {N} BETTER = {better}; ({xq/xq}, {eula/xq}, {both/xq}); ({xq}, {eula}, {both})') | |
ws.append([N, better, xq/xq, eula/xq, both/xq, xq, eula, both]) | |
n += 1 | |
print(f'{better_count}/{final//3 - initial//3 + 1}') | |
print(better_count/(final//3 - initial//3 + 1)) | |
wb.save('1mod3.xlsx') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment