Retired

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.

Strings

Stats:

CreatedJan 18, 2023
Warriors Trained10
Total Skips0
Total Code Submissions84
Total Times Completed7
C# Completions7
Total Stars0
% of votes with a positive feedback rating10% of 5
Total "Very Satisfied" Votes0
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes4
Total Rank Assessments5
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • BatCountry Avatar
Ad