Skip to content

Instantly share code, notes, and snippets.

@weatherspud
Created December 11, 2016 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weatherspud/d31e4e7dcf53042368e511d31e04012d to your computer and use it in GitHub Desktop.
Save weatherspud/d31e4e7dcf53042368e511d31e04012d to your computer and use it in GitHub Desktop.
#!/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