| Bytes | Lang | Time | Link |
|---|---|---|---|
| 007 | Vyxal | 210904T005402Z | emanresu |
| 010 | Nibbles | 250905T002528Z | Adam |
| 021 | cQuents | 250905T000655Z | Stephen |
| 013 | Pip | 210904T020530Z | DLosc |
| 080 | Rockstar | 230627T100819Z | Shaggy |
| 048 | Arturo | 230627T044135Z | chunes |
| 7625 | Vyxal | 230627T011810Z | lyxal |
| 009 | Thunno 2 J | 230626T170806Z | The Thon |
| 037 | Knight v2.0alpha | 220918T064207Z | Sampersa |
| 031 | Labyrinth | 220915T052624Z | Jo King |
| 051 | jq | 210904T073539Z | Razetime |
| 043 | jq r | 210905T122610Z | ovs |
| 043 | Python 3.8 prerelease | 210905T104134Z | Jakque |
| 035 | Vim | 210904T033001Z | DLosc |
| 045 | Python | 160109T125519Z | Sherlock |
| 007 | Stax | 190930T174402Z | recursiv |
| 023 | k4 | 190930T172342Z | scrawl |
| 069 | Lua | 190922T140646Z | Mahmoud |
| 036 | Haskell | 190929T211944Z | xnor |
| 009 | 05AB1E legacy | 190930T074159Z | Dorian |
| 046 | Mumps InterSystems | 190628T124212Z | zmerch |
| 041 | Befunge93 | 190627T125949Z | negative |
| 043 | PHP r | 190625T105536Z | Shieru A |
| 063 | Clojure | 190625T140843Z | NikoNyrh |
| 017 | APL Dyalog Classic | 190625T085536Z | ngn |
| 048 | APLNARS | 190625T073844Z | user5898 |
| 169 | JavaScript | 190625T043015Z | user8748 |
| 012 | Husk | 190405T035613Z | Esolangi |
| 157 | Brainfuck | 190403T134856Z | orthople |
| 008 | Japt | 190401T212027Z | Shaggy |
| 009 | Jelly | 190402T221651Z | Nick Ken |
| 054 | PowerShell | 190402T080326Z | mazzy |
| 035 | Perl 6 | 190402T030736Z | Jo King |
| 048 | R | 190401T212343Z | Robin Ry |
| 014 | Gaia | 190401T203923Z | Giuseppe |
| 008 | Canvas | 190401T202955Z | dzaima |
| 032 | Mathematica | 160310T200902Z | Calculat |
| 037 | Haskell | 160109T174611Z | nimi |
| 011 | Pyke | 160609T171009Z | Blue |
| 158 | Java 7 | 160411T184251Z | Poke |
| 041 | Powershell | 160331T132536Z | Jonathan |
| 028 | J | 160331T050036Z | Leaky Nu |
| 014 | MATL | 160110T053515Z | Luis Men |
| 219 | Java | 160311T051817Z | JamesENL |
| 017 | Japt | 160110T034136Z | ETHprodu |
| 033 | Perl | 160110T032153Z | type_out |
| 042 | JavaScript ES6 | 160109T131359Z | user8165 |
| 571 | JavaScript | 160109T125324Z | nicael |
| 054 | Matlab | 160109T154300Z | flawr |
| 018 | K5 | 160109T153223Z | JohnE |
| 032 | Retina | 160109T124754Z | Martin E |
| 013 | Pyth | 160109T124330Z | Adnan |
| 059 | C# | 160109T133653Z | LegionMa |
| 012 | 05AB1E | 160109T133049Z | Adnan |
| 038 | Ruby 1.9 and up | 160109T131927Z | Sherlock |
| 044 | Python | 160109T130832Z | Sp3000 |
| 046 | Mathematica | 160109T125716Z | LegionMa |
| 011 | Pyth | 160109T125027Z | orlp |
| 014 | CJam | 160109T124009Z | Peter Ta |
Vyxal, 7 bytes
Eɽ2Ǒ›øA
Eɽ # 0...2^n inclusive
2Ǒ # number of times each can be divided by 2
› # incremented, to start with 1 instead of 0
øA # and get the corresponding letter for each
# (output as a list of chars, joined into a single string)
cQuents, 21 bytes
=@a:Z~hb$))~Z
=97:Z+1
Explanation
=@a:Z~hb$))~Z first line
=@a first term is "a"
: mode sequence: given input n, output the nth term
with no input, output the sequence indefinitely
each term is
Z previous
~ concat
h ) char( )
b ) second line( )
$ current index
~ concat
Z previous
=97:Z+1 second line
=97 first term is 97
: mode sequence: given input n, output the nth term
each term is
Z the previous term
+ +
1 1
Pip, 14 13 bytes
UaLaYPOzWR:yy
Or, if 1-indexing is allowed, drop the Ua for 11 bytes: Attempt This Online!
Explanation
UaLaYPOzWR:yy
; z is lowercase alphabet; y is empty string (implicit)
Ua ; Increment the command-line argument to get the indexing right
La ; and loop that many times:
POz ; Pop the first character of z
WR:y ; Wrap it in two copies of y
Y ; Assign back to y
y ; After the loop, output the final value of y
Other 13 (or 11) byte solutions using different kinds of loops:
UaWaYyJWz@Day
UaFizHaYiWRyy
Rockstar, 80 bytes
1-indexed
listen to N
X's 0
O's ""
while N-X
cast X+97 in C
let O be+C+O
let X be+1
say O
Try it (Code will need to be pasted in)
Arturo, 48 bytes
f:$->x[(0=x)?->"a"->++++f x-1to :char x+97f x-1]
f:$->x[ ; a function named f taking an argument x
(0=x)? ; is x zero?
->"a" ; then return "a"
-> ; otherwise,
++++ ; append three things together
f x-1 ; f(x-1)
to :char x+97 ; x converted to character
f x-1 ; f(x-1)
] ; end function
Vyxal, 61 bitsv2, 7.625 bytes
¤$(nøAȮW∑
Uses 1-indexing.
Explained
Generated using Luminespire
¤$(nøAȮW∑
¤$ # Push an empty string under the input
( # For each n in the range [1, input]:
nøA # Get the nth letter of the alphabet
Ȯ # Push a copy of the item under the top of the stack. This leaves the stack as [already generated, new letter, already generated]
W∑ # Wrap and sum the stack
Thunno 2 J, 9 bytes
Oėıf2c;⁺Ä
Port of emanresu A's Vyxal answer.
Explanation
Oėıf2c;⁺Ä # Implicit input
O # Push 2 ** input
ė # Push [1..that)
ı ; # Map:
f # Prime factors
2c # Count 2s
⁺Ä # Letter of alphabet
# Implicit output
Knight (v2.0-alpha), 37 bytes
;=q+96=n+1P;=x"";W=n-nT=x++xA-q n xOx
Expanded
; = q (+ 96 (= n (+ 1 PROMPT)))
; = x ""
; WHILE (= n (- n TRUE))
= x (+ (+ x (ASCII (- q n))) x)
: OUTPUT x
Labyrinth, 31 bytes
_-)"(;;
(. ? {_
@ +}989
1_
I feel like this can be rearranged to be golfier, but a better layout eludes me. I also have a cleaner 1-indexed version which has a higher ratio of walls. This uses xnor's method of repeatedly incrementing the string and interspersing with as.
jq, 51 bytes
[range(.)+97|[.]|implode]|reduce.[]as$i("a";.+$i+.)
My life has improved significantly since I found reduce in this language.
-16 bytes from ovs.
jq -r, 43 bytes
def f:.-1|[[97]][.+1]//f+[.+98]+f;f|implode
With the capitalization pattern from the example outputs, 58 bytes:
def f:[[65]][.]//([.-1|f[]%32+96,.+66]|.+.)[:-1];f|implode
def f: ... ; define a filter named f
[[65]][.] base case, if the argument . is 0, return [65]
// otherwise
.-1|f call the filter recursively
[]%32+96 convert each codepoint to lower case
,.+66 append .+66 (. is now the filter argument -1)
[ ... ] collect all codepoints in an array
|.+. and repeat that array twice
[:-1] remove the last integer
f|implode call the filter on the input and convert the result to a string
Vim, 35 bytes
:h<_
jjYZZpqqv|yPyl/<c-r>"
xq{Dddl@-@qD
Explanation
The buffer starts with a single line containing the input integer.
:h<_
jjYZZp
Yank the lowercase alphabet from the help file. Paste it on a new line below the integer, leaving the cursor on the first character of the second line.
qq
Start recording macro q. This will be our "loop."
v|y
Using visual mode, select everything from the current character to the beginning of the line, inclusive, and yank it. This leaves the cursor on the first character of the line.
P
Paste the yanked text to the left of the cursor. The cursor is now on the last of the pasted characters.
yl
Yank that character.
/<c-r>"
x
Find the next occurrence of the just-yanked character. Delete it.
q
Stop recording the macro. Conveniently, this first time through the macro has left the alphabet unchanged. The only effect is that the cursor has moved from the a to the b.
{Dddl
Go to the beginning of the buffer. Delete the contents of the first line (the input number). Then delete the (now-empty) first line. Move the cursor one character to the right so as to start on b.
@-@q
Execute the macro N times, where N is the number we just deleted.
D
Delete the unused remainder of the alphabet.
Normally, the @-@q idiom is fraught with peril if the number has a chance of being zero, because 0 is not a valid count in Vim; instead, it is treated as a separate command that move the cursor to the beginning of the line. However, in this particular case, an input of 0 is no problem at all:
@-
Move the cursor to the beginning of the line.
@q
Execute the macro once. Recall that executing the macro with the cursor on the a leaves the alphabet unchanged and the cursor on the b.
D
Delete everything to the end of the line--which leaves only the a, exactly the output we want.
Python, 62 54 46 45 bytes
I would like to think that this code can still be golfed down somehow.
Edit: Bug fix thanks to Lynn. -1 byte thanks to squid.
a=lambda n:n and a(n-1)+chr(97+n)+a(n-1)or'a'
k4, 23 bytes
{.Q.a x{x,(1+|/x),x}/0}
x{ }/0 / do {func} x times, passing output of last iteration as input (first input is 0)
(1+|\x) / 1 + max x
x, ,x / join x either side
.Q.a / index into alphabet
executed with inputs [0,4) we get:
{.Q.a x{x,(1+|/x),x}/0}'[0 1 2 3]
("a";"aba";"abacaba";"abacabadabacaba")
Lua, 69 bytes
f=function(n)return n<1 and"a"or f(n-1)..string.char(97+n)..f(n-1)end
C++ (gcc), 58 53 bytes
string f(int n){return n--?f(n)+char(98+n)+f(n):"a";}
- 5 bytes saved by ceilingcat
Haskell, 36 bytes
tail.(iterate((:"a").succ=<<)"_a"!!)
This uses a different recursive method from most of the other answers. To get the next string in the sequence, we don't join two copies in the previous string with a new letter in between, but instead increment every letter and intersperse a's.
aba -> bcb -> abacaba
05AB1E (legacy), 9 bytes
AćsI£vDyý
Also runs with the new 05AB1E version.
code:
A push the lowercase alphabet
ć extract first character of that ["bcdefg....", "a"]
s swap both strings ["a", "bcdefg...."]
I£ drop all letters of the alphabet after the index defined by input
v for each character
D duplicate last stack entry
yý join by current letter
implicitly close for-loop and print top of stack
Mumps (InterSystems), 46 bytes
S Q="",A=65 R N F I=0:1:N{S Q=Q_$C(A+I)_Q} W Q
InterSystems' version of Mumps (some say M, InterSystems likes to call it "Cache Object Script") allows delineating loops with braces which helps keep things on a single line; GT.M would be a few characters longer.
Befunge-93, 41 bytes
1-011v $<
v::+&_:#^!_:1+v
>:0\:^,+"`"$%:<
Probably some room for improvement here.
Explanation
The sequence is generated using its recursive definition. First, we initialize the stack with the 4 values (1, input+2), (0, -1). Each pair (a, b) on the stack is an "instruction" used in generating the sequence, which, when executed, gets popped and does the following:
- if
a == 0:- if
b == -1, terminate - if
b == 0, do nothing - if
b != -1 and b != 0, printb+96as an ASCII character
- if
- if
a != 0, push(b-1, b-1), (0, b-1), (b-1, b-1)
The top two items on the stack are continuously run as a sequence-building instruction until the program terminates.
Worth noting that &+ is used the first time around to get the input, as well as every subsequent time as a decrement (because when there is no more input, & returns -1)
PHP -r, 43 bytes
register_argc_argv must be enabled for this to work.
for($a=$b=a;$argv[1]--;$a.=++$b.$a);echo$a;
PHP, 51 bytes
An anonymous function that prints the output directly.
function($n){for($a=$b=a;$n--;$a.=++$b.$a);echo$a;}
Clojure, 63 bytes
#(loop[r""i 0](if(= i %)r(recur(str r(char(+ i 97))r)(inc i))))
APL(NARS), 24 chars, 48 bytes
{⍵<0:⍬⋄k,⎕A[⍵+1],k←∇⍵-1}
test:
f←{⍵<0:⍬⋄k,⎕A[⍵+1],k←∇⍵-1}
f 0
A
f 1
ABA
f 2
ABACABA
f 3
ABACABADABACABA
f 4
ABACABADABACABAEABACABADABACABA
JavaScript, 169 bytes
x=function(n){var r="";for(var i=1;i<=Math.pow(2,n)-1;i++){for(var j=i;j>=0;j--){if(!(i%Math.pow(2,j))){r+="ABCDEFGHIJKLMNOPQRSTUVWXYZ".slice(0,n)[j];break;}}}return r;}
Try it online!
Live demo:
x=function(n){var r="";for(var i=1;i<=Math.pow(2,n)-1;i++){for(var j=i;j>=0;j--){if(!(i%Math.pow(2,j))){r+="ABCDEFGHIJKLMNOPQRSTUVWXYZ".slice(0,n)[j];break;}}}return r;}
console.log(x(prompt("Input depth of ABACABA Pattern")))
Explanation:
x = function(n){ // created function, and yes, I omitted var var r = ""; // declaring variable to be returned for (var i = 1; i <= Math.pow(2, n) - 1; i++){ // this loop creates each letter in the pattern; "Math.pow(2, n) - 1" is the length of the pattern at depth n for (var j = i; j >= 0; j--){ // this loop finds the greatest power of 2 that i is divisible by, since that can be used to find the correct character for that index if (! (i % Math.pow(2, j) ) ){ // the modulo part checks the divisibility of 2^j; the "!" replaces "=== 0" r += "ABCDEFGHIJKLMNOPQRSTUVWXYZ".slice(0,n)[j]; // appending character to r break; // exits loop once greatest power of 2 i is divisible by is found } } } return r; }
Husk, 12 bytes
!¡S+oṠ:o→▲"a
Uses 1-based indexing, which I hope is OK.
Explanation
! ( !!)
¡ iterate( )
S <*>
+ (++)
o ( )
Ṡ join$ .
: (:)
o .
→ succ
▲ maximum
"a "a"
(iterate((++)<*>(join$(:).succ.maximum))"a"!!)
Brainfuck, 157 bytes
,+>-[>++<-----]>----->>+<<<<[->>[[->>[>>>]<+<+<[<<<]>>[>>>]<]>>[>>>]<[-<<[<<<]>>[>>>]<+>>[>>>]<]+>+<<<[<<<]>>[>>>]+[>>>]<]<<<+>>[<-<<]<]>>>>[>>>]<<<<<<[<<.<]
Input is given in binary.
The basic idea is to repeatedly duplicate the current sequence (starting with "a") and to increment the last element after each iteration:
a → aa → ab
ab → abab → abac
abac → abacabac → abacabac
...
When all of this has been done the specified amount of times, the result gets printed excluding the last element.
In-depth explanation
The memory is arranged in the following way:
.---------.-.-----.----.---.-----.----.---.---
|Countdown|0|Value|Copy|End|Value|Copy|End|...
'---------'-'-----'----'---'-----'----'---'---
|--Element 1---|--Element 2---|
Countdown holds the number of copy cycles that are yet to be executed. The ABACABA sequence is stored in adjecent blocks, each made up of 3 cells. Value holds the character of the element (i.e. "A","B","C"...). The Copy flag indicates whether or not the corresponding element needs to be copied within the current copying cycle (0=copy, 1=don't). The End flag is set to 0 for the last element while it is being copied (it's 1 in all other cases).
Now to the actual (slightly ungolfed) program:
, read Countdown from input
+ add 1 to avoid off-by-one error
>-[>++<-----]>----- initialize value cell of first element to 97 ("a")
>>+ set End flag of first element to 1
<<<< move to Countdown
[ loop until Countdown hits 0 (main loop)
- decrement Countdown
>> move to Value cell of first element
[ copying loop
[ duplication sub-loop
- decrement Value cell of the element to copy
>> move to End flag
[>>>] move to End flag of the last element
<+<+ increment Copy and Value cell of last element (Copy cell is temporarily abused)
< move to End flag of second to last element
[<<<]>> move back to Copy cell of first element
[>>>]< move to Value cell of the first element where the Copy flag is 0
]
>>[>>>]< move to (abused) Copy flag of the last element
[ "copy back" sub-loop
- decrement Copy flag
<< move to End flag of second to last element
[<<<]>> move back to Copy cell of first element
[>>>]< move to Value cell of the first element where the Copy flag is 0
+ increment Value cell
>>[>>>]< move back to Copy flag of the last element
]
+>+ set Copy and End flag to 1
<<< move to End flag of second to last element
[<<<]>> move back to Copy cell of first element
[>>>]< move to Value cell of the first element where the Copy flag is 0
>+< set Copy flag to 1
>[>>>]< move to Value cell of the next element to copy
] loop ends three cells behind the last "valid" Value cell
<<<+ increment Value cell of last element
>> move to End flag
[<-<<] reset all Copy flag
< move to Countdown
]
>>>> move to End flag of first element
[>>>]<<< move to End flag of last element
<<< skip the last element
[<<.<] output Value cells (in reverse order, but that doesn't matter)
Japt, 8 bytes
;gCåÈ+iY
;gCåÈ+iY :Implicit input of integer
g :Index into
; C : Lowercase alphabet
å : Cumulatively reduce, with an initial value of an empty string
+ : Append a copy of the current value
i : Prepended with
Y : The current letter
Jelly, 9 bytes
‘R;ṭ¥/ịØa
It would be 8 were it not for the requirement for the sequence to start with zero = a.
Gaia, 14 bytes
₵aØ@⟪¤ṇ3ṁ¤+ṫ⟫ₓ
₵a | Push lowercase alphabet
Ø | push lowercase string
@ ₓ | push the input and do everything between ⟪⟫ that many times
⟪¤ | swap
ṇ | take the last (first) character
3ṁ | push the 3rd item on the stack
¤+ | swap and concatenate
ṫ⟫ | and palindromize
Canvas, 8 bytes
ø⁸╵zm{+│
7 bytes taking the index starting with 1, or hacky 6 bytes by taking input "with a trailing newline" (which together can sum up to 5 bytes)
Mathematica, 36 32 bytes
##<>#&~Fold~Alphabet[][[;;#+1]]&
Have you ever watched TWOW 11B?
Haskell, 39 37 bytes
a 0="a"
a n=a(n-1)++['a'..]!!n:a(n-1)
Usage example: a 3 -> "abacabadabacaba".
Edit: @Angs found two bytes to save. Thanks!
Pyke, 11 bytes (noncompeting)
G@QVk?tQG@:
G@ - s = alphabet[input]
QV - repeat input times:
?tQ - input -= 1
G@ - alphabet[^]
k : - s = s.replace("", ^)
Java 7, 158 bytes
class B{public static void main(String[]a){a('a',Byte.valueOf(a[0]));}static void a(char a,int c){if(c>=0){a(a,c-1);System.out.print((char)(a+c));a(a,c-1);}}}
I like to lurk around PPCG and I would enjoy being able to vote/comment on other answers.
Input is given as program parameters. This follows the same format as many other answers here in that it's a straight forward recursive implementation. I would have commented on the other answer but I don't have the rep to comment yet. It's also slightly different in that the recursive call is done twice rather than building a string and passing it along.
Powershell, 53,46,44,41 Bytes
1..$args[0]|%{}{$d+=[char]($_+96)+$d}{$d}
Pasting into console will generate erronous output on the second run since $d is not re-initialized.
Save 2 bytes by using += Save 3 bytes thanks to @TimmyD
J, 30 28 bytes (Try it online!)
I just found out that a(0) = "a", which chopped of 2 bytes.
u:97+(0:`($:@<:,],$:@<:)@.*)
Usage:
u:97+(0:`($:@<:,],$:@<:)@.*) 2
abacaba
How it works:
u:97+(0:`($:@<:,],$:@<:)@.*) n NB. pseudocode:
NB. input as n
NB. function as generate_tree
u: NB. convert_to_ASCII(
97+ NB. add_to_all(97,
(xx`yyyyyyyyyyyyyyy@.z) NB. if z then y or x:
* NB. z: n>0?
0: NB. x: 0
($:@<:,],$:@<:) NB. y:
ppppp,q,rrrrr NB. concat(p,q,r):
$:@<: NB. p:
$:@ NB. generate_tree(
<: NB. n-1)
] NB. q: n
$:@<: NB. r: generate_tree(n-1)
MATL, 14 bytes
0i:"t@whh]97+c
This uses version 8.0.0 of the language/compiler, which is earlier than the challenge.
Example
>> matl
> 0i:"t@whh]97+c
>
> 3
abacabadabacaba
Explanation
The secuence is created first with numbers 0, 1, 2, ... These are converted to letters 'a', 'b', 'c' at the end.
0 % initiallize: a(0)
i: % input "N" and create vector [1, 2, ... N]
" % for each element of that vector
t % duplicate current sequence
@ % push new value of the sequence
whh % build new sequence from two copies of old sequence and new value
] % end for
97+c % convert 0, 1, 2, ... to 'a', 'b', 'c'. Implicitly print
Edit
Java, 219 bytes
My first code golf attempt. Probably can be golf'd further, but I'm hungry and going out to lunch.
public class a{public static void main(String[]a){String b=j("a",Integer.parseInt(a[0]),1);System.out.println(b);}public static String j(String c,int d,int e){if(d>=e){c+=(char)(97+e)+c;int f=e+1;c=j(c,d,f);}return c;}}
Ungolfed:
public class a {
public static void main(String[] a) {
String string = addLetter("a", Integer.parseInt(a[0]), 1);
System.out.println(string);
}
public static String addLetter(String string, int count, int counter) {
if (count >= counter) {
string += (char) (97 + counter) + string;
int f = counter + 1;
string = addLetter(string, count, f);
}
return string;
}
}
Pretty straightforward brute force recursive algorithm, uses char manipulation.
Japt, 20 17 bytes
97oU+98 r@X+Yd +X
How it works
// Implicit: U = input integer
65oU+66 // Generate a range from 65 to U+66.
r@ // Reduce each item Y and previous value X in this range with this function:
X+Yd // return X, plus the character with char code Y,
+X // plus X.
// Implicit: output last expression
Non-competing version, 14 bytes
97ôU r@X+Yd +X
The ô function is like o, but creates the range [X..X+Y] instead of [X..Y). Test it online!
I much prefer changing the 97 to 94, in which case the output for 5 looks like so:
^_^`^_^a^_^`^_^b^_^`^_^a^_^`^_^c^_^`^_^a^_^`^_^b^_^`^_^a^_^`^_^
Perl, 33 bytes
map$\.=chr(97+$_).$\,0..pop;print
No real need for un-golfing. Builds the string up by iteratively appending the next character in sequence plus the reverse of the string so far, using the ASCII value of 'a' as its starting point. Uses $\ to save a few strokes, but that's about as tricky as it gets.
Works for a(0) through a(25) and even beyond. Although you get into extended ASCII after a(29), you'll run out of memory long before you run out of character codes:
a(25) is ~64MiB. a(29) is ~1GiB.
To store the result of a(255) (untested!), one would need 2^256 - 1 = 1.15x10^77 bytes, or roughly 1.15x10^65 1-terabyte drives.
JavaScript (ES6), 43 42 bytes
a=n=>n?a(--n)+(n+11).toString(36)+a(n):"a"
A byte saved thanks to @Neil!
Yet another simple recursive solution...
JavaScript, 65 571 bytes
n=>eval('s="a";for(i=0;i<n;i++)s+=(i+11).toString(36)+s')
Demo:
function a(n){
return eval('s="a";for(i=0;i<n;i++)s+=(i+11).toString(36)+s')
}
alert(a(3))
1 - thanks Neil for saving 8 bytes
Matlab, 54 bytes
Just a straight forward recursive implementation.
function s=f(n);s='';if n>-1;k=f(n-1);s=[k,n+97,k];end
I first thought I could do better by using anonymous functions, but it turned out to be way longer, but I thougt I still share it:
i=@(b,c)c{2-b}();
a=@(n,f)i(n<0,{@()'',@()[f(n-1,f)),n+97,f(n-1,f)]});
ba=@(n)a(n,a);
K5, 18 bytes
"A"{x,y,x}/`c$66+!
Repeatedly apply a function to a carried value ("A") and each element of a sequence. The sequence is the alphabetic characters from B up to some number N (`c$66+!). The function joins the left argument on either side of the right argument ({x,y,x}).
In action:
("A"{x,y,x}/`c$66+!)'!6
("A"
"ABA"
"ABACABA"
"ABACABADABACABA"
"ABACABADABACABAEABACABADABACABA"
"ABACABADABACABAEABACABADABACABAFABACABADABACABAEABACABADABACABA")
Retina, 37 32 bytes
$
aa
(T`_l`l`.$
)`1(a.*)
$1$1
z
The trailing linefeed is significant. Input is taken in unary.
Pyth, 14 13 bytes
Thanks to Jakube for saving a byte!
VhQ=+k+@GNk;k
A solution with 14 bytes: VhQ=ks[k@GNk;k.
Explanation:
VhQ=+k+@GNk;k
# Implicit: k = empty string
VhQ # For N in range input + 1
= # Assign k
+@GNk # Position N at alphabet + k
+k # k + above
; # End loop
k # Print k
Try it here!
C#, 59 bytes
string a(int n){return n<1?"a":a(n-1)+(char)(97+n)+a(n-1);}
Just another C# solution...
05AB1E, 12 bytes (non-competitive)
Code:
'aIGDN>.bsJl
I'll be damned. I fixed a lot of bugs thanks to this challenge haha.
Explanation:
'aIGDN>.bsJl
'a # Push the character 'a'
I # User input
G # For N in range(1, input)
D # Duplicate the stack
N # Push N
> # Increment
.b # Convert to alphabetic character (1 = A, 2 = B, etc.)
s # Swap the last two elements
J # push ''.join(stack)
l # Convert to lowercase
# Implicit: print the last item of the stack
Ruby (1.9 and up), 38 bytes
?a is a golfier way to write "a" but looks weird when mixed with ternary ?:
a=->n{n<1??a:a[n-1]+(97+n).chr+a[n-1]}
Python, 44 bytes
f=lambda n:"a"[n:]or f(n-1)+chr(97+n)+f(n-1)
Looks suspiciously might-be-golfable.
Mathematica, 46 bytes
If[#<1,"a",(a=#0[#-1])<>Alphabet[][[#+1]]<>a]&
Simple recursive function. Another solution:
a@0="a";a@n_:=(b=a[n-1])<>Alphabet[][[n+1]]<>b
Pyth, 11 bytes
u++GHG<GhQk
Simple reduction.