Beta

[BF] Character grouping

Description:

Background

Many programming languages offer built-in functionalities to group side-by-side identical elements. For example:

  • Python: groupby function in the itertools module
  • Haskell: group / groupBy function in the Data.List module
  • Ruby: chunk method

So let's make one in BF!

Task

Given a null-terminated string as input, your BF program should output a string where adjacent identical characters are grouped together and enclosed in parentheses.

For the empty input "", your program should return an empty string "" since there is nothing to group.

Examples

     Input        |        Output
----------------- | --------------------
   "aaabbbccc\0" --> "(aaa)(bbb)(ccc)"
      "112211\0" --> "(11)(22)(11)"
         "xyz\0" --> "(x)(y)(z)"
            "\0" --> ""

GLHF 😉

Algorithms

More By Author:

Check out these other kata created by Just4FunCoder

Stats:

CreatedMar 1, 2024
PublishedMar 4, 2024
Warriors Trained10
Total Skips0
Total Code Submissions16
Total Times Completed7
BF Completions7
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
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • Just4FunCoder Avatar
Ad