Your task is to take an input, for example:


And produce an output, which per this example is aaaabbbbb

a,b,4,5 means: the lowercase character "a" is repeated 4 times, and is then followed by the lowercase character "b" repeated 5 times, making the total number of characters 4+5=9

Another example: the input a,B,5,4, should produce the output aaaaaBBBB, which is: the lowercase letter "a" is repeated 5 times, followed by the uppercase letter "B" repeated 4 times.

Some more examples:

Input --> Output

a,b,4,6         --> aaaabbbbbb
a,b,c,1,2,3     --> abbccc
a,e,d,f,g,1,2,3,4,5 --> aeedddffffggggg
A,b,4,5         --> AAAAbbbbb
A,b,C,1,2,3     --> AbbCCC
A,B,c,D,1,2,3,4 --> ABBcccDDDD

Note how the output must have only the required letters, nothing else, except trailing newlines.

The format of the input should be exactly as you see in the above examples, so your code does not have to support any additional formats/styles of the input.

The output must be displayed in a format exactly as the examples show, this means no commas, spaces, etc, separating the letters. Trailing newlines are okay, if you cannot avoid them.

Standard loopholes are disallowed, and the output is case sensitive.

This is , so the shortest code in bytes wins!

  • 1
    \$\begingroup\$ will the numbers always be increasing? \$\endgroup\$
    – Maltysen
    Aug 20, 2016 at 1:08
  • 2
    \$\begingroup\$ This seems quite similar to Run Length Decoding. \$\endgroup\$
    – Dennis
    Aug 20, 2016 at 1:13
  • 5
    \$\begingroup\$ @ColdGolf Stricter input/output is a pretty trivial modification to a challenge. \$\endgroup\$
    – Suever
    Aug 20, 2016 at 1:22
  • 1
    \$\begingroup\$ Will the numbers always be one digit, as in your examples? \$\endgroup\$
    – Jordan
    Aug 20, 2016 at 2:43
  • 1
    \$\begingroup\$ @ColdGolf can we accept input as a list or list of letter-number pairs? I ask because the language I'm thinking of doesn't do well with string parsing, and it's lists look funny when typed out.... \$\endgroup\$ Aug 20, 2016 at 3:54

6 Answers 6


05AB1E, 11 bytes



',¡             # turn input into a list split at commas
   2ä           # divide that list in 2
       ø        # zip, turning the list into pairs of [letter, number]
        v       # for each pair
         y`×?   # print letter number of times

Try it online


Pyth - 14 bytes


Try it online here.


APL, 26 bytes




APL has a built-in for this, so all the code is really doing is parsing the string:

      1 2 3/'AbC'


  • ⍵~⎕D,C←',': remove all digits and commas from the input, leaving only the letters. (Since it only has to deal with single letters, this works.)
  • ∊(//)C⎕VFI⍵: using the comma as a field separator, get all valid numbers in the input.
  • /: replicate each letter by the required amount
  • 1
    \$\begingroup\$ Same basic idea: {(⍎⍵∩c)/⍵~c←⎕D,','} \$\endgroup\$
    – Adám
    Aug 28, 2016 at 19:31

Python 2 - 88 bytes

print''.join(X[i]*int(X[i+k])for i in range(k))

Edited to remove whitespace

  • \$\begingroup\$ Quoted input is acceptable, so you can do input() instead of raw_input(). Additionally, you can drop the whitespace between print and '', and between ) and for. Be sure to take a look at codegolf.stackexchange.com/q/54/45941 for more golfing suggestions! I've also changed the header to Python 2, because we typically only use "Python" for code that can run under either 2 or 3. Last but certainly not least, welcome to PPCG! \$\endgroup\$
    – user45941
    Aug 20, 2016 at 3:01
  • \$\begingroup\$ idk if it'll be shorter, but chopping in half can also be done through zip(*[iter(foo)]*2) \$\endgroup\$
    – Maltysen
    Aug 20, 2016 at 3:42

Python 2, 66 bytes

print''.join(s*y for s,y in zip(i[:l],i[l:]))

Uses every Python golfer's favourite function, zip(). Takes input with letters in quotes e.g.:


Ideone it!


PHP, 84 bytes

$b=split(',',$argv[1]);while($i<$n=count($b)/2)echo str_repeat($b[+$i],$b[$n+$i++]);

Takes the input string as the first argument as in php script.php a,B,c,3,2,6.


Not the answer you're looking for? Browse other questions tagged or ask your own question.