mardi 30 juillet 2019

Generating a Pattern Based on Percentages [on hold]

I've been given a series of values that are supposed to be displayed at a certain percentage. I'd like to know if there is an algorithm when given an arbitrary set of values with respective percentages that you can create a pattern that when repeated will equate to that value appearing for its respective percentage amount.

Example:

Given:

A @ 40%, B @ 20%, C @ 10%, D @ 10%, E @ 10%

Solution: BACADAEAB

Currently I'm doing this by hand and hard coding it whenever the values change. I know there's a formula to find the Least Common Multiple (LCM), but it relies on a Greatest Common Divisor (GCD) which seems to be trickier to code.

I don't have any code to produce the results yet, the formula I'm trying to replicate is:

lcm(v1, v2, ...) = (|v1 x v2 x ...|)/(gcd(v1, v2, ...))

Is there an algorithm I can program to produce the formula above or is there a better way to do this?

Aucun commentaire:

Enregistrer un commentaire