33
1
Introduction
Let's observe the following string:
AABBCCDDEFFGG
You can see that every letter has been duplicated, except for the letter E
. That means that the letter E
has been de-duplicated. So, the only thing we need to do here is to reverse that process, which gives us the following un-de-duplicated string:
AABBCCDDEEFFGG
Let's take a harder example:
AAAABBBCCCCDD
You can see that there is an uneven number of consecutive B
's, so that means that one of the BB
was de-duplicated from the original string. We only need to un-de-duplicate this letter, which gives us:
AAAABBBBCCCCDD
The challenge
Given a non-empty de-duplicated string, consisting of only alphabetic characters (either only uppercase or only lowercase), return the un-de-duplicated string. You can assume that there will always be at least one de-duplicated character in the string.
Test cases
AAABBBCCCCDDDD --> AAAABBBBCCCCDDDD
HEY --> HHEEYY
AAAAAAA --> AAAAAAAA
N --> NN
OOQQO --> OOQQOO
ABBB --> AABBBB
ABBA --> AABBAA
This is code-golf, so the shortest valid submission in bytes wins!
@mbomb007 Yes, that would result into
AABBBB
. – Adnan – 2016-12-15T22:35:04.277@mbomb007 Ah, I was not aware of that. Thanks! – Adnan – 2016-12-15T22:38:42.693
1I'm not sure I understand the challenge. Why does
ABBB
map toAABBBB
, notAABBBBBB
? – Dennis – 2016-12-15T23:14:33.2872@Dennis If you seperate each group of characters into groups of 2, you would get the following:
A BB B
. The characters that aren't paired (and therefore not duplicated) need to be duplicated, resulting inAA BB BB
, which is the un-de-duplicated string. – Adnan – 2016-12-15T23:33:17.370Got it. Thanks! – Dennis – 2016-12-15T23:43:15.327
8So: Ensure that every run of characters has an even number of elements by adding at most one element to the run? – Mad Physicist – 2016-12-16T12:13:08.543
1@MadPhysicist Yes, that is correct – Adnan – 2016-12-16T14:30:56.573