Jelly, (削除) 43 41 40 25 (削除ここまで) 24 bytes
3RŒḄIμṙ4R¤
0ị=1ị$aOIṠ¢e@
TryItOnline
Or all test cases (plus "RULES")
###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.
All but (1) may 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μṙ4R¤ - Link 1, make the four rotations of [1,1,-1,-1] (no arguments, AKA niladic)
3R - range(3) -> [1,2,3]
ŒḄ - bounce -> [1,2,3,2,1]
I - increments -> [1,1,-1,-1]
μ - monadic chain separation
¤ - nilad followed by link(s) as a nilad
4R - range(4) -> [1,2,3,4]
ṙ - rotate left by -> [[1,-1,-1,1],[-1,-1,1,1],[-1,1,1,-1],[1,1,-1,-1]]
0ị=1ị$aOIṠ¢e@ - Main link: word
$ - last two links as a monad
0ị - element at index 0 (last character)
= - equals?
1ị - element at index 1 (first character)
O - cast to ordinals
I - increments - the alphabet deltas
Ṡ - sign
e@ - exists in (@ = reversed arguments)
¢ - call last link (2) as a nilad
Jonathan Allan
- 115.4k
- 8
- 68
- 293