35
2
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!
29I think
b
cartwheels intoq
, doesn't it?d
andp
are also cartwheel buddies. They key is that they rotate, not flip. – Engineer Toast – 2017-08-02T17:24:04.817Another testcase suggestion:
uwuwuwuwuwu
– user41805 – 2017-08-02T17:44:17.55319Why
bqb
but notpdp
? – aschepler – 2017-08-03T00:33:13.050@aschepler I messed up. – MD XF – 2017-08-03T22:33:39.190
2Since
dpd
,pdp
and such don't work, I think you should have them in the test cases with a falsy answer. – trlkly – 2017-08-04T01:05:30.473