Jelly, (削除) 43 41 40 (削除ここまで) 18 bytes
3RŒḄIṙ
4RÇ€
OIṠ¢e@
###How?
An infinity word has:
- the same first and last letter;
- length 5;
- no equal letters next to each other;
- sum of its four alphabet deltas equal to zero;
- sum of its four alphabet deltas signs equal to zero;
- two positive alphabet deltas or two negative alphabet deltas in a row.
This can all be boiled down to a condition that the alphabet delta signs are some rotation of [1,1,-1,-1] (where the sign of 0 is 0)
###How?
3RŒḄIṙ - Link 1, make a rotation of [1,1,-1,-1]: n
3R - range(3) -> [1,2,3]
ŒḄ - bounce -> [1,2,3,2,1]
I - increments -> [1,1,-1,-1]
ṙ - rotate left by n (e.g. n=1 -> [1,-1,-1,1])
4RÇ€ - Link 2, make the four rotations of [1,1,-1,-1] (no arguments, AKA niladic)
4R - range(4) -> [1,2,3,4]
Ç€ - call the last link as a monad for €ach
OIṠ¢e@ - Main link: word
O - cast to ordinals
I - increments - the alphabet deltas
Ṡ - sign
e@ - exists in (@ = reversed arguments)
¢ - call last link as a nilad
Jonathan Allan
- 115.4k
- 8
- 68
- 293