# input: space-separated table of focus names and ai_weight # output: SVG graph on stdout, numerical probabilities on stderr import sys from fractions import Fraction from collections import namedtuple from math import sin, cos, pi, sqrt Focus = namedtuple('Focus', ['name', 'will_do']) focuses = [Focus(name, Fraction(will_do)) for (name, will_do) in [x.strip().split() for x in sys.stdin]] f_prob = {f.name: 0 for f in focuses} working_set = list(focuses) prob_accu = Fraction(0) rings = [] while working_set: highest_remaining = max(x.will_do for x in working_set) if highest_remaining <= 0: break top_group, lower_group = [], [] for focus in working_set: if focus.will_do == highest_remaining: top_group.append(focus) else: lower_group.append(focus) next_highest = max(x.will_do for x in lower_group) if lower_group else 0 sector_probability = (Fraction(1) - pow(next_highest/highest_remaining, len(top_group))) * (Fraction(1) - prob_accu) for f in top_group: f_prob[f.name] += sector_probability / len(top_group) prob_accu += sector_probability rings.append((highest_remaining, sector_probability, list(top_group))) # align ring sectors to get coherent shapes stride = int((len(working_set)-len(top_group)) / len(top_group) + 0.5) working_set = [Focus(top_group.pop(0).name, next_highest)] while len(top_group) or len(lower_group): for _ in range(stride): if len(lower_group): working_set.append(lower_group.pop(0)) if len(top_group): working_set.append(Focus(top_group.pop(0).name, next_highest)) print(f_prob, file=sys.stderr) colors = ['#edd400', '#f57900', '#c17d11', '#73d216', '#3465a4', '#75507b', '#cc0000', '#d3d7cf', '#ff00ff', '#ffff00'] print('') prob_accu = 0 for will_do, prob, items in rings: radius = 190 * sqrt(1 - prob_accu) print(f'') print(f'{will_do}') n = len(items) if n == 1: idx, = [i for i, e in enumerate(focuses) if e.name == items[0].name] print(f'') else: for i, focus in enumerate(items): idx, = [i for i, e in enumerate(focuses) if e.name == focus.name] print(f'') prob_accu += prob print('')