Problem 577. Repopulate the City
For any population p of positive integers between pmin and pmax, we can calculate histogram count n for a list of evenly dividing divisors d. Here's how it works.
Consider the population p = [10, 12, 15, 11, 20, 11]. For the list of divisors d = [2, 3, 5] we get a histogram count n of [3, 2, 3]. That is, three of the numbers in the population are evenly divisible by 2, two are evenly divisible by 3, and three are evenly divisible by 5.
You will face the inverse problem. Given a histogram count corresponding to a list of divisors, produce a population of positive integers that fits the distribution. Your answer will not be unique and can be provided in any order. It just has to match the distribution. The elements of p can be no less than pmin and no greater than pmax.
Example:
pmin = 5
pmax = 10
d = [1 2 3 4 5]
n = [8 3 4 2 2]
One answer (of many possible): p = [5 5 6 8 8 9 9 9]
Solution Stats
Problem Comments
-
3 Comments
@bmtran (Bryant Tran)
on 13 Apr 2012
It looks like there's an error in the test suite; test cases 3 and 4 have different length d and n vectors.
Ned Gulley
on 13 Apr 2012
Oof! I hate it when that happens. Fixed it. Thanks for the note.
Ben Westcott
on 13 Jul 2022
Great head-scratcher!
Solution Comments
Show commentsProblem Recent Solvers49
Suggested Problems
-
Make a random, non-repeating vector.
9151 Solvers
-
Create a vector whose elements depend on the previous element
654 Solvers
-
Find out missing number from a vector of 9 elements
294 Solvers
-
315 Solvers
-
785 Solvers
More from this Author50
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!