43
\$\begingroup\$

Description

Output the rhyme scheme for a very long Terza Rima.

Input

None.

Output

ABA
BCB
CDC
DED
EFE
FGF
GHG
HIH
IJI
JKJ
KLK
LML
MNM
NON
OPO
PQP
QRQ
RSR
STS
TUT
UVU
VWV
WXW
XYX
YZY

Rules

You can pick between separating stanzas with whitespace or newlines, so either:

ABA BCB...

OR

ABA
BCB
...

A single trailing whitespace allowed per line and one trailing newline allowed.

Output can be either uppercase or lowercase.

This is , so the shortest code in bytes for each language wins.

\$\endgroup\$
9
  • 4
    \$\begingroup\$ Is a list of lines okay? \$\endgroup\$ Dec 18, 2017 at 16:23
  • 6
    \$\begingroup\$ According to en.wikipedia.org/wiki/Terza_rima your ending is wrong. It should end with either Z or ZZ. \$\endgroup\$
    – Chris
    Dec 18, 2017 at 18:28
  • \$\begingroup\$ Can there be additional output beyond the rhyme scheme? This might save me a few bytes. \$\endgroup\$
    – NK1406
    Dec 18, 2017 at 23:02
  • \$\begingroup\$ @NK1406 Nope sorry. \$\endgroup\$
    – LiefdeWen
    Dec 19, 2017 at 7:13
  • 1
    \$\begingroup\$ @totallyhuman String array is fine. \$\endgroup\$
    – LiefdeWen
    Dec 19, 2017 at 7:14

90 Answers 90

2
\$\begingroup\$

Ruby, 32 bytes

puts (?A..?Y).map{|c|c+c.next+c}

Try it online!


If a list of strings is valid output:

Ruby, 31 bytes

->{(?A..?Y).map{|c|c+c.next+c}}

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Befunge, 26 bytes

:"A"+:,:1+,,1+:64*`#@_55+,

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Vyxal 3 j, 4 bytes

moᵛṅ

Try it Online!

same as vyxal 2 but the byte lost from not having vectorized mirror is saved from the one byte capital alphabet builtin

\$\endgroup\$
2
\$\begingroup\$

Zsh, 40 bytes

eval '<<<$[[##36]'{13366..45358..1333}\]

Attempt This Online!

\$\endgroup\$
1
\$\begingroup\$

Retina, 24 bytes


ABA
;{:G`
T`_p`p`[^Y]..

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ 21 bytes but suffers from trailing newlines... \$\endgroup\$
    – Neil
    Dec 18, 2017 at 14:57
  • \$\begingroup\$ @Neil Yeah, you don't even need the `.... Getting rid of those trailing newlines is really annoying though. I'm hoping to make printing in loops a bit more flexible and convenient in Retina 1.0. \$\endgroup\$ Dec 18, 2017 at 15:13
1
\$\begingroup\$

brainfuck, 73 bytes

+++++++++++++[>+++++>+++++<<-]>>+<<<<+++++[>++>+++++<<-]>>[>.>.+<.+<-<.>]

Try it online!

\$\endgroup\$
1
\$\begingroup\$

T-SQL 189 154 bytes

declare @ char(26)='ABCDEFGHIJKLMNOPQRSTUVWXYZ',@i int=1,@@ char while(@i<26)begin  set @@=substring(@,@i,1)print @@+substring(@,@i+1,1)+@@ set @i=@i+1 end
\$\endgroup\$
1
\$\begingroup\$

Perl 5, 27 24 bytes

say$\=$_++,$_.$\for A..Y

previous solution

say$_,chr 1+ord,$_ for A..Y

Try it online

\$\endgroup\$
1
\$\begingroup\$

Recursiva, 13 bytes

{B25"PpZ~}(;}

Try it online!

\$\endgroup\$
1
\$\begingroup\$

J (repl), 18 bytes

u:65+(,>:,])"+i.25

Try it online!

Can be made into a function for +4 bytes:

(u:65+(,>:,])"+i.25)"_

Other solutions:

u:|:65 66 65+/i.25

Explanation

u:65+(,>:,])"+i.25
              i.25     range [0, 25)
     (     )"+         on each number:
      ,  ,               create a list composed of the number,
       >:                the number + 1
          ]              and the number
                       this gives the 2D list [0 1 0] [1 2 1] ...
  65+                  add 65 to each element
u:                     convert to characters
\$\endgroup\$
1
\$\begingroup\$

Batch, 99 bytes

@set s=ABCDEFGHIJKLMNOPQRSTUVWXYZ
:l
@echo %s:~0,2%%s:~0,1%
@set s=%s:~1%
@if not %s%==Z goto l

Only 10 bytes shorter than a literal...

\$\endgroup\$
1
\$\begingroup\$

MATL, 12 11 10 bytes

1 byte off thanks to Luis Mendo, by using 5B (5 in binary) to push a [1 0 1] pattern.

66:90!5B-c

Try it online!

\$\endgroup\$
0
1
\$\begingroup\$

Kotlin, 42 bytes

{('A'..'Y').map{println("$it${it+1}$it")}}

Try it online!

or

{('A'..'Y').map{println(""+it+(it+1)+it)}}

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Shnap, 35 bytes

for c:'A'..'Z'println(""+c+(c+1)+c)

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Pushy, 9 bytes

Z1Z25:QKh

Try it online!

Explanation:

Z1Z          \ Make the stack [0, 1, 0]
   25:       \ 25 times do:
      Q      \    Print the stack, as indexes into the uppercase alphabet
       Kh    \    Increment all values
\$\endgroup\$
1
\$\begingroup\$

V, 16 bytes

¬azòóˆˆ/±²±\r²òd

Try it online!

Hexdump:

00000000: ac61 7af2 f388 882f b1b2 b15c 72b2 f264  .az..../...\r..d

Recursive Regular Expressions for the win!

\$\endgroup\$
1
\$\begingroup\$

Add++, 46 44 bytes

L,"ABCDEFGHIJKLMNOPQRSTUVWXYZ"dBREpBR2DBcEJn

Try it online!

Who needs all these "palindromise" functions?

2 bytes saved thanks to DLosc!

How it works (old version)

L,     - Create a nilary lambda function.
  "…"  - Push the uppercase alphabet;     STACK = ['ABC…XYZ']
  d    - Duplicate;                       STACK = ['ABC…XYZ' 'ABC…XYZ']
  BR   - Reverse;                         STACK = ['ABC…XYZ' 'ZYX…CBA']
  2D   - Duplicate from below;            STACK = ['ABC…XYZ' 'ZYX…CBA' 'ABC…XYZ']
  Ep   - Dequeue each;                    STACK = ['BCD…XYZ' 'YXW…CBA' 'BCD…XYZ']
  $BR$ - Reverse the middle string;       STACK = ['BCD…XYZ' 'ABC…WXY' 'BCD…XYZ']
  Bc   - Zip;                             STACK = [['A' 'B' 'A'] … ['Y' 'Z' 'Y']]
  EJ   - Join each;                       STACK = ['ABA' … 'YZY']
  n    - Join with newlines               STACK = ['ABA…YZY']
\$\endgroup\$
0
1
\$\begingroup\$

Clean, 60 bytes

import StdEnv
t=foldr(+++)""[{c,c+one,c,' '}\\c<-['a'..'y']]

Try it online!

If a list of Char ([Char]) is okay instead of a String ({#Char}) (they look the same when printed bare), then we can save a few bytes and use:

Clean, 53 bytes

import StdEnv
t=flatlines[[c,c+one,c]\\c<-['a'..'y']]

Try it online!

If a list of String ([{#Char}]) representing the lines is acceptable, then we can save even more and use:

Clean, 45 bytes

import StdEnv
t=[{#c,c+one,c}\\c<-['a'..'y']]

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Funky, 38 bytes

fori=65i<90i++print("%c%c%c"%{i i+1i})

Naïve solution, not very exciting, but it works.

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Japt, 11 6 bytes

Returns an array of lines.

;BäÈiZ

Try it


Explanation

  • ;B is the uppercase alphabet.
  • äÈ gets each pair of consecutive characters in a string and passes them through a function.
  • iZ prepends the current element to the first character of the current element.

Alternative, 6 bytes

;Bã mê

Try it


Explanation

  • ã splits the alphabet string into an array of consecutive character pairs.
  • m maps over the array.
  • ê palindromises the current element.
\$\endgroup\$
1
  • \$\begingroup\$ Array of lines is allowed. \$\endgroup\$
    – LiefdeWen
    Dec 19, 2017 at 7:16
1
\$\begingroup\$

Brain-Flak classic, 160 150 118+2=120 bytes with -A flag

((((((()()()){}){}){}){}){}())<>(((((()()()()())){}){}){}){({}[])<>([{}])[({}())][({}[])]({}())[((()()()()()){})]{}<>}

Try it online!

The separator is a newline.

-8 bytes thanks to DJ

-32 bytes thanks to DJ

\$\endgroup\$
3
  • \$\begingroup\$ The first 50 bytes are rather redundant. in general, rather than doing (...)(({}){}) you can do ((...){}) to save 4 bytes. And of course, this can be nested several times. To push 'a' I would do ((((((()()()){}){}){}){}){}()) instead. \$\endgroup\$
    – DJMcMayhem
    Dec 19, 2017 at 18:05
  • \$\begingroup\$ You can also use brain-flak.github.io/integer to autogolf large integers for you. \$\endgroup\$
    – DJMcMayhem
    Dec 19, 2017 at 18:05
  • \$\begingroup\$ And minus 32 bytes \$\endgroup\$
    – DJMcMayhem
    Dec 19, 2017 at 18:08
1
\$\begingroup\$

dc, 24 bytes

65[ddP1+dPrPdAP90>M]dsMx

Try it online!

Pretty straightforward. Start with ASCII value for A, duplicate it a couple of times, print it, increment it and duplicate this, print it, swap the top-of-stack, print (the unincremented number), print a line feed, keep going as long as we haven't made it to Z (90).

\$\endgroup\$
1
\$\begingroup\$

Python 3, 55 bytes

' '.join(map(lambda x:"%c"*3%(x-1,x,x-1),range(66,91)))

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ -2 : ' '.join(map(lambda x:"%c"*3%(x,x+1,x),range(65,90))) \$\endgroup\$
    – Jakque
    May 22, 2021 at 9:59
1
\$\begingroup\$

Cubically, 34 bytes

FRF'-2(+345@+33-5@-33+5@-33200@1)6

Try it online!

It was hard... At least it's doable. (without too much hardcoding)

Other Rubik's algorithm may lead to shorter sequence.

Some alternatives I tried (which is, unfortunately, longer):

35 bytes: Try it online!

36 bytes: Try it online!


Explanation:


FRF'      Rubik's cube algorithm. This algorithm has the property of make face
          value 1 equal to 10. (character of code of `\n`)
-2        Subtract face value 2 (which is 25) from the notepad.
(    )6   While notepad is nonzero:
+345        Add 90 to notepad.
@           Print notepad value.
+33-5       Add 1 to notepad.
@           Print notepad value.
-33+5       Subtract 1 from notepad.
@           Print notepad value.
-33200      Subtract 89 from notepad.
@1          Print face value 1 (which is 10, '\n')
\$\endgroup\$
1
\$\begingroup\$

Premier, 18 bytes

:| s |ns:'Z~*AUc
A

Try it online!

Explanation

The second line just defines the data for the program. So, starting wtih A on the stack...

:| s |ns:'Z~*AUc
:|   |n            print the following format:
  .                   TOS
   s                  TOS + 1
    .                 TOS
                   this prints out ABA, for example
       s:'Z~*      If the next char is not 'Z'
             A        append it to the data
              Uc   print a newline

This repeats until the next character is Z, at which point there is no data left, and the program terminates.

\$\endgroup\$
1
\$\begingroup\$

vim, 48 28 keystrokes

:h<_EnterjjYZZPqqy2llpi ESCl@qq@qD

My first attempt at golfing in vim

Explanation

:h<_EnterjjYZZP                    Insert the alphabet by copying it from the help manual
qq                                  Define a macro `q`:
 y2l                                 Copy the first two characters (relative to the cursor)
 lp                                  Paste after the copied characters (ABCDE -> ABABCDE)
 i Esc                             Insert a space (ABABCDE -> ABA BCDE)
 l@q                                 Run the macro again with the cursor after the space
q@q                                 End the macro defenition and run it
D                                   Remove the last Z
\$\endgroup\$
1
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 83 82 81 79 72 bytes

R	&UCASE POS(I) LEN(1) . L @I LEN(1) . R	:F(END)
	OUTPUT =L R L	:(R)
END

Try it online!

I think I'm finally getting the hang of @!

SNOBOL variables are initialized automatically to "" which is also equivalent to 0. So the first time the interpreter sees line R, the line is:

&UCASE POS(0) LEN(1) . L @I LEN(1) . R  :F(END)

which finds a LENgth 1 string starting at POSition 0 (the beginning of the string), assigning the matched string to L. Then we assign the position of that match to I using @, which has been incremented by 1 because of the LEN(1) . L. The next character is then matched and assign it to R, and output L R L. This continues until I is 25, since then LEN(1) . R fails to match, as L would be Z.

\$\endgroup\$
1
\$\begingroup\$

Go, 56 Bytes

func n(){for i:=65;i<90;i++{Printf("%c%c%c\n",i,i+1,i)}}

Ungolfed and readable:

func n() {
    for i := 65; i < 90; i++ {
        Printf("%c%c%c\n", i, i + 1, i)
    }
}

Try it online!

\$\endgroup\$
1
\$\begingroup\$

PHP, 72 bytes

-2 bytes because yay assumed values!

-15 bytes thanks to Francisco Hahn

<?php $x=ABA;for($i=0;$i<75;$i++){if($i%3==0){echo$x." ";}$t=$x[$i%3];$x[$i%3]=++$t;}?>

Try it online!

Takes the string "ABA" through a for loop which loops through each character and increments it. Displays the current value of the string every 3 times.

\$\endgroup\$
1
  • \$\begingroup\$ $x=ABA;for(;$i<75;$i++){echo($i%3)?"":$x." ";$t=$x[$i%3];$x[$i%3]=++$t;} 72 \$\endgroup\$ May 8, 2018 at 13:42
1
\$\begingroup\$

Go, 60 56 bytes

func t(){for i:=65;i<90;i++{Printf("%c%c%c\n",i,i+1,i)}}

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.