The Scala forum at coderanch is pretty dormant. Recently, I came across a question that does k-reduction on Strings. I decided to give it a try in Scala and here is what I came up with:
What do you guys think? Could it be even simpler while at the same time readable?
So what is
String k-reduction?
Given a string consisting of a,b and c's, we can perform the following operation: Take any two adjacent distinct characters and replace it with the third character. For example, if 'a' and 'c' are adjacent, they can replaced with 'b'.
What is the smallest string which can result by applying this operation repeatedly