Is this string a letter doing a cartwheel?
sed 4.2.2, 30 + 1 -r
= 43 31 bytes
Saved 12 bytes thanks to @Neil by shortening the first line
/nu|wm|qb/!d
/^((.).)\1*\2$/!d
Try it online!
Deletes input if falsey, otherwise does nothing to the input.
Explanation
With the -r
flag, we do not need to use \(
and \)
for capturing groups and this saves bytes.
/nu|wm|qb/! # On every line that does not match this regex
d # Delete
/^((.).)\1*\2$/! # On every line that does not math
^((.).) # the first two characters at the beginning of the line
\1* # repeated
\2$ # with the first character at the end of the line
d # Delete
JavaScript (ES6), 82 78 77 bytes
Saved 1 byte by using two falsy values, as suggested by ThePirateBay and MD XF.
([c,...s],S='bqwmun')=>s.reduceRight((r,a)=>r&a==S[S.search(c)^++k&1],k=s>'')
Test cases
let f =
([c,...s],S='bqwmun')=>s.reduceRight((r,a)=>r&a==S[S.search(c)^++k&1],k=s>'')
console.log('Truthy ...')
console.log(f("nun" )) // -> truthy
console.log(f("nunun" )) // -> truthy
console.log(f("wmw" )) // -> truthy
console.log(f("bqbqbqbqbqb" )) // -> truthy
console.log(f("ununununu" )) // -> truthy
console.log('Falsy ...')
console.log(f("nunununu" )) // -> falsy
console.log(f("wmwun" )) // -> falsy
console.log(f("v^v^v" )) // -> falsy
console.log(f("AVAVA" )) // -> falsy
console.log(f("OOO" )) // -> falsy
console.log(f("nunwmwnun" )) // -> falsy
console.log(f("nun unun" )) // -> falsy
console.log(f("nunwmw" )) // -> falsy
console.log(f("nnuunnuunnuu")) // -> falsy
console.log(f("m" )) // -> falsy
Python 3, 111 bytes
-2 bytes thanks to Mr. Xcoder.
lambda s:s[0]==s[-1]and any(any({*s[::2]}=={i[j]}and{*s[1::2]}=={i[j<1]}for j in[0,1])for i in['nu','mw','bq'])
Try it online!