Challenge inspiration was this that I saw somewhere:
The word "nun" is just the letter n doing a cartwheel
Your challenge is to take a string and determine if it is the first letter doing a cartwheel.
Rules
A string is a letter doing a cartwheel if:
- The first letter is the same as the last letter. (The letter can't land on its head.)
- The string alternates between cartwheeling letters every one character.
The cartwheeling letters are n
and u
, m
and w
, b
and q
. Note that n
and w
together are not cartwheeling letters, and neither are w
and b
.
- You will take a string using any of our standard input methods.
- You will output a truthy value if the string is a cartwheeling letter, and a falsy value if it is not. Output can be done using any standard output methods.
Additional rules:
- Only lowercase cartwheel letters
n
/u
/m
/w
/b
/q
need to be handled. - You may assume that input is never empty.
- A one-character string is not a valid cartwheel.
Test cases
Input -> Output
nun -> truthy
nunun -> truthy
nunununu -> falsy
wmw -> truthy
wmwun -> falsy
bqbqbqbqbqb -> truthy
v^v^v -> falsy
AVAVA -> falsy
OOO -> falsy
ununununu -> truthy
nunwmwnun -> falsy
nun unun -> falsy
nunwmw -> falsy
nnuunnuunnuu -> falsy
nwnwnwnwn -> falsy
m -> falsy
nunuuunun -> falsy
Winner
As with code-golf, the shortest code (in each language) wins!
b
cartwheels intoq
, doesn't it?d
andp
are also cartwheel buddies. They key is that they rotate, not flip. \$\endgroup\$uwuwuwuwuwu
\$\endgroup\$bqb
but notpdp
? \$\endgroup\$dpd
,pdp
and such don't work, I think you should have them in the test cases with a falsy answer. \$\endgroup\$