[BF] Memory Limited: Majority rules!!! (Using only 4 cells)
Description:
Story
The ASCII-Nation is in a state of chaos!!! After the recent impeachment of their president, Moe 'Ģ'
Barkay for corruption, the ASCII characters now urgently need a new leader.
The problem? Due to the budget cut, corruption, poor encoding choices, blah blah... they are stuck with a very basic BF computer that has only 4 memory cells. Uh oh, can you find a way to sort out the ballots and save the day?
Task
The votes are represented as a string, with each character in the string counting as one vote for that character.
Luckily for you, there seems to be one character that received overwhelming support, appears more than 50% in the string (let's call this the dominating character).
Given a null-terminated string (length 1
-99
) containing one dominating character, return that character using only 4 memory cells.
You don't need to worry about invalid inputs such as ""
or "wwxyz"
or "xxxyyy"
.
Examples
Input string | Dominating
------------- | ------------
"11121314" --> '1' (appeared 5 times out of 8, 62.5% appearance)
"++[+>+++<]" --> '+' (appeared 6 times out of 10, 60% appearance)
"dbbbb" --> 'b' (appeared 4 times out of 5, 80% appearance)
"a" --> 'a' (100% appearance, also being the only candidate)
Program size is limited to less than 1000 BF commands []+-<>,.
, their poor 4-cell BF computer cannot handle that many inputs.
GLHF!
Similar Kata:
Stats:
Created | Feb 18, 2024 |
Published | Feb 28, 2024 |
Warriors Trained | 6 |
Total Skips | 0 |
Total Code Submissions | 5 |
Total Times Completed | 5 |
BF Completions | 5 |
Total Stars | 0 |
% of votes with a positive feedback rating | 100% of 4 |
Total "Very Satisfied" Votes | 4 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 4 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 6 kyu |