35
2
This challenge is about printing the abacaba sequence of a specific depth.
Here is a diagram of the first 5 sequences (a(N)
is the abacaba sequence of depth N, upper/lowercase is just to show the pattern, this is not needed in the output of your program):
a(0) = A
a(1) = aBa
a(2) = abaCaba
a(3) = abacabaDabacaba
a(4) = abacabadabacabaEabacabadabacaba
...
a(25) = abacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabahabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabaiabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabahabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabajabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabahabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabaia...
As you can probably tell, the n'th abacaba sequence is the last one with the n'th letter and itself again added to it. (a(n) = a(n - 1) + letter(n) + a(n - 1)
)
Your task is to make a program or function that takes an integer and prints the abacaba sequence of that depth. The output has to be correct at least for values up to and including 15.
3Wouldn't the sequence be undefined after ₂₅? – LegionMammal978 – 2016-01-09T13:04:28.687
@Legion OP's mentioned that "The output has to be correct at least for values up to and including 15", so it doesn't matter. – nicael – 2016-01-09T13:26:09.743
3@nicael I know, I was just wondering how (∞) would be defined. – LegionMammal978 – 2016-01-09T13:29:04.397
Huh. I had been contemplating posting this challenge. – quintopia – 2016-01-09T15:16:13.000
2Also known as the ruler sequence (but with letters instead of numbers), for something more easily Google-able. – user253751 – 2016-01-10T06:00:42.757
Does the input have to be in decimal? – user253751 – 2016-01-10T06:05:55.467
Why is a(0)="a"? Why not ""? – CalculatorFeline – 2016-03-10T20:11:42.303
1@CatsAreFluffy Because this is how the famous sequence is defined. – mbomb007 – 2016-03-10T21:47:02.513
4For what it's worth, any valid solution to this problem is also the solution to the Towers of Hanoi puzzle for N disks. – Jeff Zeitlin – 2019-04-02T11:59:25.013
3Can we use 1-based indexing instead of 0-based indexing? – Esolanging Fruit – 2019-04-03T17:21:46.010