40
\$\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\$
  • 4
    \$\begingroup\$ Is a list of lines okay? \$\endgroup\$ – totallyhuman Dec 18 '17 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 '17 at 18:28
  • \$\begingroup\$ Can there be additional output beyond the rhyme scheme? This might save me a few bytes. \$\endgroup\$ – NK1406 Dec 18 '17 at 23:02
  • \$\begingroup\$ @NK1406 Nope sorry. \$\endgroup\$ – LiefdeWen Dec 19 '17 at 7:13
  • 1
    \$\begingroup\$ @totallyhuman String array is fine. \$\endgroup\$ – LiefdeWen Dec 19 '17 at 7:14

72 Answers 72

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
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Perl 5, 27 24 bytes

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

previous solution

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

Try it online

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Recursiva, 13 bytes

{B25"PpZ~}(;}

Try it online!

| improve this answer | |
\$\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
| improve this answer | |
\$\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...

| improve this answer | |
\$\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!

| improve this answer | |
\$\endgroup\$
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!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Shnap, 35 bytes

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

Try it online!

| improve this answer | |
\$\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
| improve this answer | |
\$\endgroup\$
1
\$\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!

| improve this answer | |
\$\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!

| improve this answer | |
\$\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']
| improve this answer | |
\$\endgroup\$
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!

| improve this answer | |
\$\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!

| improve this answer | |
\$\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.
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Array of lines is allowed. \$\endgroup\$ – LiefdeWen Dec 19 '17 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

| improve this answer | |
\$\endgroup\$
  • \$\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\$ – James Dec 19 '17 at 18:05
  • \$\begingroup\$ You can also use brain-flak.github.io/integer to autogolf large integers for you. \$\endgroup\$ – James Dec 19 '17 at 18:05
  • \$\begingroup\$ And minus 32 bytes \$\endgroup\$ – James Dec 19 '17 at 18:08
  • \$\begingroup\$ @DJMcMayhem thanks \$\endgroup\$ – Christopher Dec 19 '17 at 18:28
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).

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Python 3, 55 bytes

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

Try it online!

| improve this answer | |
\$\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.

| improve this answer | |
\$\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
| improve this answer | |
\$\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!

| improve this answer | |
\$\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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ $x=ABA;for(;$i<75;$i++){echo($i%3)?"":$x." ";$t=$x[$i%3];$x[$i%3]=++$t;} 72 \$\endgroup\$ – Francisco Hahn May 8 '18 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!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

K (oK), 17 16 bytes

Solution:

`c$010b+/:65+!25

Try it online!

Explanation:

Might be a better way, but this is what I came up with:

`c$010b+/:65+!25 / the solution
             !25 / til 25 => 0..24
          65+    / add 65 -> 65..89 
       +/:       / add left to each right
   010b          / boolean array of 0 1 0
`c$              / cast to ASCII characters
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

GolfScript, 17 bytes

90,65>''+{.).(n}%

Try it online!

Explanation

90,65>            # Yield the uppercase alphabet
      ''+         # Convert to a string
         {     }% # For every codepoint in the string:
          .)      # Push the codepoint incremented
            .(    # Push the codepoint decremented
              n   # Push a newline
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

naz, 60 bytes

8a8m2x1v2d3m7s2x2v1x1f1v1a1o1a1o1s1o2x1v0m9a1a1o1v3x2v1l0x1f

Explanation (with 0x commands removed)

8a8m2x1v                               # Set variable 1 equal to 64 ("@")
2d3m7s2x2v                             # Set variable 2 equal to 89 ("Y")
1x1f                                   # Function 1
    1v                                 # Load variable 1 into the register
      1a1o1a1o1s1o                     # Output the next line of the rhyme scheme
                  2x1v                 # Store the value of the register in variable 1
                      0m9a1a1o         # Output a newline
                              1v       # Load variable 1 into the register
                                3x2v1l # Jump back to the start of the function
                                       # if the value in the register is less than variable 2
1f                                     # Call function 1
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

SOGL V0.12, 7 bytes

ZZ«Z⁰Ij

Try it Here!

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Standard ML (MLton), 62 bytes

fun$90=""| $n=implode(map chr[n,n+1,n,32])^ $(n+1);print($65);

Try it online!

Ungolfed:

fun f 90 = ""
  | f  n = implode(map chr[n,n+1,n,32]) ^ f(n+1);

print(f 65);
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

VBA, 40 Bytes

Anonymous VBE immediate window function that takes no input and outputs to the vbe immediate window.

For i=65To 89:a=Chr(i):?a;Chr(i+1)a:Next
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Acc!!, 66 bytes

Count i while i-25 {
	i+65
	Write _
	Write _+1
	Write _
	Write 0
}

Try it online!

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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