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.
4Related – AdmBorkBork – 2016-11-03T21:01:29.307
Can it be a function which returns a list of terms up to N? – FlipTack – 2016-11-03T21:21:29.583
Do we have to print the result or can we return a list of strings from a function? – nimi – 2016-11-03T21:21:41.253
Wait, so it doesn't have to work for n=1? – Socratic Phoenix – 2016-11-03T22:39:01.703
Also, can we use 0-based indexing? – Socratic Phoenix – 2016-11-03T22:45:36.607
@SocraticPhoenix The input isn't really an index, but the number of strings we should print. – Dennis – 2016-11-04T01:00:35.247
@Dennis ahh... I misunderstood, there goes my solution :( – Socratic Phoenix – 2016-11-04T01:34:10.777
printing the entire sequence seems like a trivial addition to the challenge that doesn't add any substance to the questions. print element(n) would be much more desirable IMO – downrep_nation – 2016-11-05T16:32:25.990