I'm in the middle of learning PHP, and the following list-related issue has occurred. Language doesn't really matter, so I'll give it to you in pseudo-code. Of course, the answers to the pseudo codes are beautiful.
Let's say there is a list of two different repeating elements - for example, two separate characters. So my list looks something like this:
myList = [C, C, D, C, D, D, D, C, C, D, C, D, C, C, ...]
However, this is not the form I want. Instead, the list should look like this:
myList* = [CC, D, C, DDD, CC, D, C, D, CC, ...]
myList* = shorten(myList)
What is the most elegant way to turn a one-character list into one that contains continuous lines of subsequent characters as its elements? My solution seems pretty crap to me, given that it includes multiple nested if statements, various state variables, and other nasty things.
Pseudo code away! Thanks a lot in advance for any implementation
shorten()
you are leaving me.