Government Percentage (retired)
Description:
Government Percentage
A governmental agency recently released the source code for one of their official apps.
One of the functions is intended to return the text content of an indicator bar consisting of ten "rounds," filled or empty, to reflect a percentage value.
Here was their implementation:
private static string GetPercentageRounds(double percentage)
{
if (percentage == 0)
return "⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪";
if (percentage > 0.0 && percentage <= 0.1)
return "🔵⚪⚪⚪⚪⚪⚪⚪⚪⚪";
if (percentage > 0.1 && percentage <= 0.2)
return "🔵🔵⚪⚪⚪⚪⚪⚪⚪⚪";
if (percentage > 0.2 && percentage <= 0.3)
return "🔵🔵🔵⚪⚪⚪⚪⚪⚪⚪";
if (percentage > 0.3 && percentage <= 0.4)
return "🔵🔵🔵🔵⚪⚪⚪⚪⚪⚪";
if (percentage > 0.4 && percentage <= 0.5)
return "🔵🔵🔵🔵🔵⚪⚪⚪⚪⚪";
if (percentage > 0.5 && percentage <= 0.6)
return "🔵🔵🔵🔵🔵🔵⚪⚪⚪⚪";
if (percentage > 0.6 && percentage <= 0.7)
return "🔵🔵🔵🔵🔵🔵🔵⚪⚪⚪";
if (percentage > 0.7 && percentage <= 0.8)
return "🔵🔵🔵🔵🔵🔵🔵🔵⚪⚪";
if (percentage > 0.8 && percentage <= 0.9)
return "🔵🔵🔵🔵🔵🔵🔵🔵🔵⚪";
return "🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵";
}
Because you are a beginning programmer, you can do better!
First, fix the defect where a percentage is returned as 10% higher than it is. Then refactor or reimplement this function into the fewest lines you can. Bonus style for not including the emoji in the source.
What fixed looks like:
< 10% should produce "⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪"
>= 10% should produce "🔵⚪⚪⚪⚪⚪⚪⚪⚪⚪"
>= 90% should produce "🔵🔵🔵🔵🔵🔵🔵🔵🔵⚪"
100% should produce "🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵"
Values less than 0 should be treated as zero, and values greater than 100 should be treated as 100.
Watch out how you count: 🔵 is longer than ⚪ - the blue-filled circle is 4 bytes, whereas the white empty circle is 3 bytes.
Similar Kata:
Stats:
Created | Jan 18, 2023 |
Warriors Trained | 10 |
Total Skips | 0 |
Total Code Submissions | 84 |
Total Times Completed | 7 |
C# Completions | 7 |
Total Stars | 0 |
% of votes with a positive feedback rating | 10% of 5 |
Total "Very Satisfied" Votes | 0 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 5 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 7 kyu |
Lowest Assessed Rank | 8 kyu |