H
H
huko2015-10-03 18:20:08
Python
huko, 2015-10-03 18:20:08

How to build a sequence of repetitions depending on the percentage?

Help, I'm dumb.
It's about the radio station.
Input data:
X - the total number of airs (variable value)
Y - % rotation of the song in X (variable value)
you need to make a playlist taking into account the % rotation of each song, and distribute it evenly.
As a result, I want to get a function, for example, at the input of which X = 4, Y = 50, returned {1: True, 2: False, 3: True, 4: False}i.e. with a 50% percentage rotation, the song gets into every second broadcast.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xmoonlight, 2015-10-03
@huko

Air Download: L=(Y/100*X)/X=2/4=0.5
Distribution:

last=0;
flags=array();
for (i=1; i<=X;i++)
  if ((i*L-last)>=1) {
                       last=i*L; 
                           array_push(flags,true);
} else array_push(flags,false);

(PHP code)

M
Mintormo, 2015-10-03
@Mintormo

A familiar problem. A similar one was offered, by the way, at the internal selection stage for the HeadHunter programmer school in 2014 ;) Read here . Don't forget to read the comments too. There are some useful solutions there too.
I especially advise you to try the solution in the very last comment at the bottom of the link.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question