My youngest son formulated a letter pattern the other day.

For ‘a': ‘a'
For ‘b': ‘ab’ (the pattern for ‘a’, twice, with every other ‘a' replaced with a ‘b'.
For ‘c’: ‘abac’ (the pattern for ‘b', twice, with every other ‘b’ replaced by a ‘c’)
For ‘d’: ‘abacabad’ (the pattern for ‘c’ twice, with every other ‘c’ replaced by a ‘d’.


Your challenge:

Write code that generates the teddyPattern for any letter up to ‘z’ (the output for which has a length of 33,554,432 characters, ending in a single ‘z’).

Your code can accept either a letter as input, or that letter’s position in the alphabet, at your discretion.

The output should be a string, in lowercase or uppercase at your discretion.

For the sake of comparison, I wrote a version in Mathematica that takes 113 bytes, suggesting somebody is going to do this in about six bytes with a golfing language.

I’ve tagged this as a ‘recursion’ challenge because I suspect a lot of implementations will use recursion, but I’m keen to see what interesting solutions arise from different approaches.

Shortest byte count wins, but I plan to call out interesting or excellent solutions that are more verbose as well.

  • 2
    \$\begingroup\$ This is a dupe of this one, with the only difference that you only take the first half of the output including the middle character. Also, taking a letter instead of a number is just added complexity. \$\endgroup\$ – Erik the Outgolfer Apr 1 '19 at 20:05

Browse other questions tagged or ask your own question.