Beta

[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!

Restricted
Algorithms

More By Author:

Check out these other kata created by Just4FunCoder

Stats:

CreatedFeb 18, 2024
PublishedFeb 28, 2024
Warriors Trained6
Total Skips0
Total Code Submissions5
Total Times Completed5
BF Completions5
Total Stars0
% of votes with a positive feedback rating100% of 4
Total "Very Satisfied" Votes4
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Total Rank Assessments4
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • Just4FunCoder Avatar
Ad