Perl, 45 +1 = 46 bytes
+1 byte for -n flag
$a=a,$b=b;say($a),($a,$b)=($b,$a.$b)for 1..$_
Slight improvement over the existing 49-byte solution, but developed separately. The parentheses for say($a)
are necessary because otherwise, it interprets $a,($a,$b)=($b,$a.$b)
as the argument of say
which outputs more junk than we need.
Perl, 42 bytes
$b=<>;$_=a;say,y/ab/bc/,s/c/ab/g while$b--
A separate approach from the above solution:
$b=<>; #Read the input into $b
$_=a; #Create the initial string 'a' stored in $_
say #Print $_ on a new line
y/ab/bc/ #Perform a transliteration on $_ as follows:
#Replace 'a' with 'b' and 'b' with 'c' everywhere in $_
s/c/ab/g #Perform a replacement on $_ as follows:
#Replace 'c' with 'ab' everywhere in $_
, , while$b-- #Perform the operations separated by commas
#iteratively as long as $b-- remains truthy
I'm not yet convinced I can't combine the transliteration and replacement into a single, shorter operation. If I find one, I'll post it.