Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python3.5
import math
die = 6
mean = sum(range(1, die + 1)) / die
variance = sum([i * i for i in range(1, die + 1)]) / die - mean ** 2
max_roll = 30
for n in range(1, max_roll + 1):
best_diff = None
best_b = None
for b in range(0, math.ceil(math.sqrt(n - 1)) + 2):
if n % 2 == b % 2:
continue
diff = abs(b**2 + 1 - n)
actual_sd = math.sqrt(n * variance)
approx_sd = math.sqrt(b * b * variance + variance)
# print('DEBUG n: {} b: {}: diff: {}'.format(n, b, diff))
if best_diff is None or diff < best_diff:
best_b = b
best_diff = diff
best_actual_sd = actual_sd
best_approx_sd = approx_sd
a = int(mean * (n - best_b - 1))
sd_change = best_approx_sd - best_actual_sd
print(u'{}d6: d6 × {} + d6 + {}'.format(n,
best_b,
a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment