# How to Determine the Minimum Universe Required for a Given Percentage

Here’s a fun math problem that I composed for fun today, inspired by the recent polls feature that Instagram released earlier this week:

If 47% of respondents answered affirmative, what is the minimum number of total respondents necessary such that rounding the affirmatives to the closest integer would result in that percentage? Express the answer in terms of a formula that could be applied to any percentage from 1-99.

You can’t solve this algebraically, but you *can* solve it algorithmically. Here’s how you’d do that in JavaScript:

```
const minimumUniverse = (knownPercent) => {
knownPercent = parseInt(knownPercent);
if (!(knownPercent > 0 && knownPercent < 100)) {
return 'Please enter a number between 0 and 100';
}
for (let i = 1; i < 100; i++) {
for (let j = i + 1; j <= 100; j++) {
const currentPercent = Math.round((i / j) * 100);
if (currentPercent < knownPercent) {
break;
} else if (currentPercent === knownPercent) {
return `${knownPercent}% equates to ${i} out of ${j}`;
}
}
}
};
```

Then you could just call it like this:

```
minimumUniverse(47);
```

This outputs the following:

47% equates to 7 out of 15

Pretty cool.

Thursday, October 5, 2017 ☕