Skip to content
{{ message }}

Instantly share code, notes, and snippets.

# weatherspud/fireball_approx.py

Created Dec 11, 2016
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
 #!/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))
to join this conversation on GitHub. Already have an account? Sign in to comment