Good point. Also, the last two solutions do not work well if the number of array elements are odd. For instance, if we have 11 unique numbers it 5 should be A, 5 B and 1 dash. But both of them print 6 "A"s and 4 "B"s and no dash. I tried to play around with the ranges but could not resolve it. I think 50% is the maximum that we want to go to be able to divide the population of numbers into two categories. Therefore, I am not worry about 75% or higher unless there is another use for this little script.
| [reply] |
My solution didn't have a problem with 50% of 11 per say. My solution always gave the wrong answer. (The OP confused me by saying 10% should give B - B - - - - A A - when that's the output for 20%.) Fixed.
my $portion = 0.50;
my @array = (1..11);
B B B B B - A A A A A
Same goes for codeacrobat's answer.
| [reply] [d/l] [select] |