21
Title misspelled on purpose. Read more to find out why.
Your task: given a delimited string or list including the characters A,B,C,D
, output the indexes of all the adjacent equal characters. Output can be multiple strings/integers on multiple lines, a list/array, or a delimited string.
All output should be in a list or string, or multiple printed lines. Each printed line, if there are multiple, should only contain 1 string or number. Trailing whatevers are okay.
Standard methods of input/output. Standard loopholes apply.
For example, the input 'ABCDDCBA'
should output 3,4
or 4,5
, depending on whether it is 0- to 1- indexed, because those numbers are the indexes of D
and the D
next to it.
Test cases:
Test cases have input given as a single string, and output as a ,
-delimited string. Outputs are 0-indexed, add 1 to every outputted item to get it to be 1-indexed.
Input: 'ABCDCABCD'
Output: ''
Input: 'AABBCCDD'
Output: '0,1,2,3,4,5,6,7'
Input: 'ABCDDDCBA'
Output: '3,4,5'
Input: 'ABBCDD'
Output: '1,2,4,5'
This is code-golf, so shortest code wins!
Can we have a trailing delimiter in the output? – Business Cat – 2017-04-11T15:37:02.893
@BasicSunset Sure – Comrade SparklePony – 2017-04-11T15:38:18.697
Must output indices be in order? – Luis Mendo – 2017-04-11T15:39:41.930
@LuisMendo No, they do not. – Comrade SparklePony – 2017-04-11T15:49:07.473
"If you chose to output multiple strings/integers, each must only have one number in them" - so, specifically, is an output of a list of lists separating the runs not acceptable (for example
[[0,1],[2,3],[4,5],[6,7]]
for your example 2), or is that OK since there is a single containing list? – Jonathan Allan – 2017-04-11T17:23:48.8401@JonathanAllan That is okay because it outputs only one list. – Comrade SparklePony – 2017-04-11T17:25:11.793
2Can indices of consecutive characters appear multiple times? E.g. for the third test case, is
3,4,4,5
valid as well? – Luke – 2017-04-11T18:18:30.877@Luke Yes, that is okay. – Comrade SparklePony – 2017-04-11T18:19:48.067
1Can you add a test case that doesn't have symmetrical matches? E.g.
AABBCD
->
1,2,3,4
– Riley – 2017-04-11T18:25:44.313@fəˈnɛtɪk Sorry, but this is not allowed. – Comrade SparklePony – 2017-04-11T20:04:35.967
Can it output as a list – fəˈnɛtɪk – 2017-04-11T20:06:08.213
@fəˈnɛtɪk "Output can be multiple strings/integers on multiple lines, a list/array, or a delimited string." Yes, it can output as a list. – Comrade SparklePony – 2017-04-11T20:09:39.213
Is it OK for the resulting list to contain empty elements? – raznagul – 2017-04-12T12:12:08.097
@raznagul Sorry, but that is not okay. – Comrade SparklePony – 2017-04-12T12:27:31.567