A sestina is a format of poem that follows an interesting pattern that we can generate. It has six stanzas of six lines each, where the last words of each line in the first stanza make up the line endings in each successive stanza, rotated in a set pattern. (There's also a three-line stanza at the end, but we won't worry about that.) Take a look at the first three stanzas of Elizabeth Bishop's creatively named Sestina:
September rain falls on the house.
In the failing light, the old grandmother
sits in the kitchen with the child
beside the Little Marvel Stove,
reading the jokes from the almanac,
laughing and talking to hide her tears.
She thinks that her equinoctial tears
and the rain that beats on the roof of the house
were both foretold by the almanac,
but only known to a grandmother.
The iron kettle sings on the stove.
She cuts some bread and says to the child,
It's time for tea now; but the child
is watching the teakettle's small hard tears
dance like mad on the hot black stove,
the way the rain must dance on the house.
Tidying up, the old grandmother
hangs up the clever almanac
Note how each line ends with one of the six words "house," "grandmother," "child," "stove," "almanac," or "tears." Not only that, but the words are ordered in the pattern 6–1—5–2—4–3, relative to the previous stanza. It ends up looking like a spiral:
We're still a few years away from programmatically generating a full sestina, but we can create a template featuring the end words of each stanza in proper order. Write a program or function that, given the six line ending words, outputs the blueprint for a sestina, following these rules. Here is the expected result for the input
house grandmother child stove almanac tears:
house grandmother child stove almanac tears tears house almanac grandmother stove child child tears stove house grandmother almanac almanac child grandmother tears house stove stove almanac house child tears grandmother grandmother stove tears almanac child house
The first stanza is the words in original order, the second stanza is in the order 6-1-5-2-4-3 from the first. The third stanza is that order relative to the second, and so on, all the way to stanza 6.
Assume that the input words will always be only letters, uppercase or lowercase. You can take them as an array of strings or a single string delimited by a non-letter character (space, newline, etc.). In the output, lines are separated by newlines (
0x0A), and stanzas separated by two newlines. A trailing newline is acceptable.
This is code-golf, so shortest code in bytes wins. That being said, it may be shorter to compress the whole poem's structure, but I'd like to see some solutions that base each stanza on the previous.