[Question]
  [
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](/questions/tagged/code-golf "show questions tagged 'code-golf'"), the shortest code (in each language) wins!
  
[Answer]
# [sed 4.2.2](https://www.gnu.org/software/sed/), 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!](https://tio.run/##K05N@f9fP6@0pjy3JqlQXzGFSz9OQ0NPU08zxlArxkgFKPL/v2MYEHL5@/tz5ZXmKZQCCRADDEGM8txyKAWWKYdCrrI4IOQq5wJKgMTBgCupEA654AZxlcLNAyr@l19QkpmfV/xftwgA "sed 4.2.2 – 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
```
[Answer]
## 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
```
[Answer]
# [Python 3](https://docs.python.org/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!](https://tio.run/##TU1dC4MwDHz3V@Stdjiw25usv6TLoOJklVk/Wici/vbO6DbGkdxdLiTt5B@NPYdSXsNT13mhwWVOpSilU0eB2hag7RRTzQensuyEi5SzURUua0gz8Te8CFzKpocKjFVpIpCTM@SYHVjC6nFteceQB3933oEESixLgGgXI21ttPu8@4Hs67aCxGA/YBhF30ew3c2g7Y31cRkbzsMb "Python 3 – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 63 bytes
```
lambda s:s[:3]in'ununqbqbwmwm'and s==s[:2]*max(len(s)/2,1)+s[0]
```
[Try it online!](https://tio.run/##dY5NC4JAEIbP7a8YvKyWUtlN8CBRp05ZJ5VYU0lwp9Z1sX69uREWfcx7eZnheZjLrTmd0e0KP@4qxtOMgfRk5C2SEqlChSIVactbThlmIH2/v7nJmLOrWeVoSmvq2nNrIqNZ0jW1yg9HJnMJPkQE@jF6g2GDoU1Kl1Q8oitvhxgkIaRglfzi1UCrT4fQHUWfB36pS2yAOg7stvsVLINwFYLjUFKca9BWKBFeL3pk9CTihtpQmHprvWvWwSb853n79beouwM)
[Answer]
# [Python 3](https://docs.python.org/3/), 71 bytes
```
lambda n:''.join(sorted({*n[1::2]}|{*n[::2]}))in"nu,mw,bq"*(n==n[::-1])
```
[Try it online!](https://tio.run/##TY7dCoJAEIXvfYrBm92VNbDuFjboCbzrxgwUlTZy/NtNonp22zUjOQznG4Y5M@1DXxrcTZU8TbeszosMUBCyuTYK6dD0uizoM8AkEmKbvl8OZ2JMoY@G1yPPOz@gKKWbhFHKJl0OegAJCUGDhIOzFVg5Hutxse8s7xa55n62cnA4WjmI49iZWUdYt@v/bFjdWeIRjfkVST3Pq5oeFCiE@UsBba9QU8VJuCe8ooqx6QM "Python 3 – Try It Online")
*-1 thanks to @HyperNeutrino and **-13** thanks to @ovs*
If the above is found to fail for any test case, there is an alternative:
```
lambda n:(sorted(list({*n[1::2]}.union({*n[::2]})))in[[*'nu'],[*'mw'],[*'bq']])*n[0]==n[-1]
```
[Try it online!](https://tio.run/##TY7LCoMwEEX3fsXskoiW2u4EC/0Cd92kKSgqDdTxlVRK6bfbifYhl3DuPLiT9mGuDe6nKjlPt6zOiwww5kPTm7LgNz0Y/vRRRnG8U6@NRd3g3JhrIYRGKX2GlqmAWI8L844pJWhtq5IEZRipyZSDGSABScvIAnBYGZLzIyUsWGZ595Mr7xeSM8cTyZk0TR3sOoRIAf90WF36HEC09vuY8jyvanrQoBHmf8bQ9hoN1wELDyyouBZiegM "Python 3 – Try It Online")
---
# Explanation
* `''.join(sorted(list({*n[1::2]}).union({*n[::2]}))))` - Gets the characters at odd indexes and the characters at even indexes, de-duplicates them and sorts the list formed by their union.
* `in'nu,mw,bq'` - Checks if they are valid cart-letter combinations.
* `n[0]==n[-1]` - Checks if the first character is the same as the last one.
[Answer]
# JavaScript (ES6), 40 bytes
```
s=>/^(nu|un|bq|qb|wm|mw)+$/.test(s+s[1])
```
Checks to see if the input string concatenated with the second character of the input string is a repeating string of the same pair of cartwheel characters.
Tests:
```
[
  "nun",
  "nunun",
  "nunununu",
  "wmw",
  "wmwun",
  "bqbqbqbqbqb",
  "v^v^v",
  "AVAVA",
  "OOO",
  "ununununu",
  "nunwmwnun",
  "nun unun",
  "nunwmw",
  "nnuunnuunnuu",
  "nwnwnwnwn",
  "m",
  "nunuuunun"
].forEach( x=>console.log( x, (s=>/^(nu|un|bq|qb|wm|mw)+$/.test(s+s[1]))(x) ) )
```
[Answer]
# Clojure, 156 bytes
```
(fn[w](let[s["nu""wm""bq"]c #(= 1(count(set %)))e #(take-nth 2 %)r #(and(c(e %))(c(e(drop 1 %))))](and(=(first w)(last w))(r w)(some #(=(set w)(set %))s))))
```
This was deceptively difficult! I ended up having to break it down into 3 sub problems:
* Is the first letter the same as the last?
* Do the letters repeat?
* Are all the letters a part of one of the valid sets?
I certainly didn't win, but this was a good morning exercise! Full explanation below:
```
(defn cartwheel? [word]
  (let [; Valid Character Sets
        cs ["nu" "wm" "bq"]
        
        ; Is the list composed of only a single character?
        count-1? #(= 1 (count (set %)))
        
        ; Grabs every other element of the list
        every-other #(take-nth 2 %)
        
        ; Do the characters repeat? Works by checking if every other element is the same, then drops the first letter
        ; to check all the odd indexed characters
        repeating? #(and (count-1? (every-other %))
                         (count-1? (every-other (drop 1 %))))]
    ; Do all the predicates hold?
    (and (= (first word) (last word))
         (repeating? word)
         ; Is the set of letters in the word part of some set of the valid characters?
         (some #(= (set word) (set %)) cs))))
```
[Answer]
## Haskell, ~~80~~ 78 bytes
```
f s|l<-length s=odd l&&l>1&&any((==s).take l.cycle)(words"un nu mw wm bq qb")
```
[Try it online!](https://tio.run/##PYzLCoMwEEV/5RJK0EWF7ptCv8Bdly1RYxWT8RHTIPTf0yhaDjMDw72nkbZTWodQw3719awVvecGVvRVBc25vl04l7QkiRA2zWbZKeisXEqt0sT3U2WZI5CD8fAGxYixYCmCkS1BYJhamnGCkQPqeLcGGG2d/47E8irw8VWMO/g8I7g/IsjzHO6fjiuGd8HrMK0OIueOAfkdGBZ@ "Haskell – Try It Online")
How it works:
```
l<-length s        -- let l be the length of the input string
f s         =      -- return True, if
    odd l          -- l is odd and
    l > 1          -- l is greater than 1 and 
    any            -- any of the following is also True
      (     )(words "  ...  ")
                   -- apply the function to each of the words "un", "nu" ... "qb"
           cycle   --  infinitely repeat the word
      take l       --  take the first l characters
     (==s)         --  and compare to s
```
[Answer]
# [Python 2](https://docs.python.org/2/), 45 bytes
```
lambda s:s[2:]+s[1:3]==s>s[:2]in'bqbunuwmw'
```
[Try it online!](https://tio.run/##bZDLboMwEEXX8BUjb0IUWil0Z8mR@gVIXbQLSiOT8rBkDPWjiFU@nZo64ZHEV174zNXMHbe9rhoRDQX5HDits28KCqskwulOJXv8khKiDirBUcrEJvvJzkaYc1d3m6GrGM9hj32PM5EDAUm7IxOt0cHW92iYhScyVp5Vy9k/01SWubbOEyFIS6OrHvmezJXhI82ahgdFQLfW2komNCToQzaixCgE9MbKSmOUJs5PiOuWhkBDhwZhBEzn6QBuhG/xXLjBVldcUK563672qIfFqx7ObP/jqqX598vqzvz6bnVH4zhezXPULMOtItsgl20ms30fpxWXdN5lpsKY613Q7qKVtwZ4EG1MZcxNhj8 "Python 2 – Try It Online")
The spaces in the string are `DEL` characters.
[Answer]
# [Retina](https://github.com/m-ender/retina), 24 bytes
```
G`nu|mw|bq
^((.).)\1*\2$
```
Outputs 1 for truthy, 0 for falsy.
Port of Cows quack's answer.
[Try it online!](https://tio.run/##K0otycxL/P/fPSGvtCa3vCapkCtOQ0NPU08zxlArxkjl//@80rzy3HIgCQA "Retina – Try It Online")
[Answer]
## [Grime](https://github.com/iatorm/grime), 28 bytes
```
e`..-#!"nu\|bq\|mw"oTv&..v+.
```
[Try it online!](https://tio.run/##Sy/KzE39/z81QU9PV1lRKa80piapMKYmt1wpP6RMTU@vTFvv///SPCAEAA "Grime – Try It Online")
Prints `1` for truthy inputs and `0` for falsy ones.
## Explanation
Grime syntax resembles regular expressions, and a Grime program specifies a pattern that may or may not match a rectangle of characters.
```
e`..-#!"nu\|bq\|mw"oTv&..v+.
e`                            Match input against pattern:
      !                       Does not
     #                        contain
  ..                          a 2-character substring
    -                         which is not
       "nu\|bq\|mw"           any of these strings
                   oT         potentially reversed,
                     v&       AND
                       ..     two characters
                         v+   one or more times
                           .  then one more character.
```
Some features of Grime that helped shorten this:
* Normally a character literal must be escaped with a backslash, but `""` changes this: syntax elements are escaped but literals are not. Without the quotes, the part that enumerates the character pairs would be `(\n\u|\b\p|\m\w)oT`.
* Unary operators that follow a binary operator (here `-`) act on its result: `..-#!"…"oT` is equivalent to `(..-"…"oT)#!`.
* The `v`s lower the precedence of the syntax elements that follow them. A lone `&` has higher precedence than `-`, but `v&` has lower. Similarly, `..+` is parsed as `.(.+)`, but `..v+` is equivalent to `(..)+`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 23 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
*This took more work than one might think!*
```
“nmbuwq”iÐ€o⁵IAs2⁼€3,3Ȧ
```
A monadic link taking a list of characters and returning `1` (truthy) or `0` (falsey).
**[Try it online!](https://tio.run/##y0rNyan8//9Rw5y83KTS8sJHDXMzD0941LQm/1HjVk/HYqNHjXuAPGMd4xPL/v//n1eaBwA "Jelly – Try It Online")** or see a [test suite](https://tio.run/##y0rNyan8//9Rw5y83KTS8sJHDXMzD0941LQm/1HjVk/HYqNHjXuAPGMd4xPL/h9uBzIf7u4Gqi4pKi3JqAQy0hJzioH03HCgFBeIOLrncHsWkAbK6dqBJA4tcf//P1oprzRPSQdEImggBDLLc8shJFgiqRAOgbyyOCAE0o5hQAik/f39gWQpkm4gBdQKN1QBYT7E3Ly80lIYBnHLoRDIzlWKBQA "Jelly – Try It Online").
### How?
Finds the index of each character of the input in the 1-indexed list of characters `nmbuwq`. This string is arranged such that the indexes of pairs are three apart, as such the incremental difference of the indexes for valid cartwheels will be repetitions of one of `[-3,3]` or `[3,-3]`.
When an item is not found in a list by the "index of" atom, `i`, it returns `0`, which would pair unfound characters with `b`, making input like `bxbxb` truthy. So `0`s are replaced by `10` a value more than three away from any other value prior to checking for validity.
```
“nmbuwq”iÐ€o⁵IAs2⁼€3,3Ȧ - Link: list of characters, s
         Ð€             - map across c in s:
        i               -   first index of c in (1-indexed; 0 if not present)
“nmbuwq”                -   literal "nmbuwq"
            ⁵           - literal 10
           o            - logical or (vectorises - replace any 0s with 10s)
             I          - incremental differences (i.e. deltas)
              A         - absolute value (vectorises)
               s2       - split into chunks of 2 (possibly with a single remainder)
                   3,3  - pair three with three = [3,3]
                 ⁼€     - equals? for €ach (1 if so, otherwise 0 - including a single 3)
                      Ȧ - any and all? (0 if any 0s or if empty, 1 otherwise)
```
[Answer]
# [Python 2](https://docs.python.org/2/), 69 bytes
```
lambda x:any([x in p*len(x)for p in'nu','mw','bq'])*len(x)%2*len(x)>2
```
[Try it online!](https://tio.run/##bVCxCoMwFNz7FVlKtKSLo6DQpatL6WItKI1UiM9okqpfbxNNqynlSHh37/JeOD7KZwPBVEa3ieV18cjREOYweumAKkD8wCh4g182HeJawKAwwXWvr6LFmW/b@8AWcTBJKqSI0lRbARN06RTNCJrpH0GZgeicM7GIvZm9ejSdH62GorXY2l53Dcd2umo4SpIkDleb/ds/6ZXws1NzpP6Iy2c3Eij1OW6jt3DU@suynQnYJEc6KhSTJvs5yJB3FcilhY8xJqVnan96Aw "Python 2 – Try It Online")
[Answer]
# [Pyth](http://pyth.readthedocs.io), 27 bytes
```
&qeQhQ/"nu,mw,bq"S+{%2tQ{%2
```
[Test Suite.](http://pyth.herokuapp.com/?code=%26qeQhQ%2F%22nu%2Cmw%2Cbq%22S%2B%7B%252tQ%7B%252&input=%22MWNUNU%22&test_suite=1&test_suite_input=%27nun%27%0A%27nunun%27%0A%27nunununu%27%0A%27wmw%27%0A%27wmwun%27%0A%27bqbqbqbqb%27%0A%27v%5Ev%5Ev%27%0A%27AVAVA%27%0A%27OOO%27%0A%27ununununu%27%0A%27nunwmwnun%27%0A%27nun+unun%27%0A%27nunwmw%27%0A%27nnuunnuunnuu%27&debug=0)
Outputs `1` for truthy and `False` or `0` for falsy, as the OP allowed in chat.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 27 bytes
```
Ḋm2Qµ³m2Q;Ṣe“nu“mw“bq”ȧ³⁼U¤
```
[Try it online!](https://tio.run/##y0rNyan8///hjq5co8BDWw9tBlLWD3cuSn3UMCevFEjklgOJpMJHDXNPLD@0@VHjntBDS/7//6@UVwqGSgA "Jelly – Try It Online")
# How it works
```
Ḋm2Qµ³m2Q;µṢe“nu“mw“bq”ȧ³⁼U¤  Main link; z is the argument
Ḋ                             z[1:]
 m2                           z[1::2]
   Q                          deduplicate(z[1::2])
    µ                         New Chain
     ³                        z
      m2                      z[::2]
        Q                     deduplicate(z[::2])
         ;                    deduplicate(z[1::2]) + deduplicate(z[::2])
          Ṣ                  Sort the result
           e                 Is it an element of the following?
            “nu“mw“bq”       ["nu", "mw", "bq"]
                      ȧ      It has the correct characters and:
                       ³  ¤  Nilad followed by links as nilad
                       ³     z
                        ⁼      == 
                         U        z[::-1]
                          ¤  [End chain]
```
[Answer]
# [Python 2](https://docs.python.org/2/), 103 bytes
```
lambda x:len(x)>1and{x[0],x[1]}in[{i,j}for i,j in zip('ubw','nqm')]and x==(-~len(x)/2*(x[0]+x[1]))[:-1]
```
[Try it online!](https://tio.run/##PY3PDoIwDIfve4rduin@gSMJJj4BNy@ICQSJM6yiMpkafHXsFOiXX5c07bf62ZwuGPRltO@rTOdFxm1YHVFYufEzLN42WaeeTfy0U5i8lXfuysuN08sV8peqBZi8BQ/wqkGmdMFtFInF5@9YBTPhDHNnkDIJF37a/wTuHADQIKOMnWCtbl1olF8n2ONAsO2OYHEcMzPtU6P1QcFHl7MgGjOG6XaAafp3ea8r1QjYI8iwvilsRCmUlHyq/gs "Python 2 – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 47 bytes
```
g ¦U¬o ª`q¿nwm`ò má c aU¯2)<0?0:UÅë ä¥ ©Uë ä¥ e
```
[Try it online!](https://tio.run/##y0osKPn/P13h0LLQQ2vyFQ6tSig8tD@vPDfh8CaF3MMLFZIVEkMPrTfStDGwN7AKPdx6eLXC4SWHliocWhkKY6b@/6@UW56rBAA "Japt – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 88 bytes
```
lambda x:[len(x)%2,x[:2]in'nu,un,bq,qb,mw,wm',len(set(x[::2])),len(set(x[1::2]))]==[1]*4
```
`len(x)%2`: an even-length string can't end on the first character
`x[:2] in`: check for any of the 6 valid beginning pairs
`len(set())`: get the length of the sets of characters at 0,2,4... and 1,3,5...
Returns `True` if the list of evaluations is equal to [1,1,1,1], else `False`.
[Try it online!](https://tio.run/##K6gsycjPM/7/PycxNyklUaHCKjonNU@jQlPVyM5ApyLayig2M089r1SnNE8nqVCnMEknt1ynPFddB6SqOLVEA6gEqEZTE0nAECISa2sbbRirZfL/f14pGAIA "Python 3 – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/), 55 + 1 (-p) = 56 bytes
```
$c={"nuunmwwmbppb"=~/./g}->{$l=chop};$_=/^($l$c)+$/&&$c
```
[Try it online!](https://tio.run/##K0gtyjH9/18l2bZaKa@0NC@3vDw3qaAgScm2Tl9PP71W165aJcc2OSO/oNZaJd5WP05DJUclWVNbRV9NTSX5///ccijkMrI0BEIuIyDgyisFw3/5BSWZ@XnF/3V9TfUMDA3@6xbkAAA "Perl 5 – Try It Online")
Prints the "upside down" version of the first character for true, nothing for false.
[Answer]
# PHP, 59+1 bytes
```
<?=preg_match('#^(nu|un|mw|wm|bq|qb)\1+$#',$argn.$argn[1]);
```
Run as pipe with `-F`.
partly regex solution, 101+1 bytes:
```
for($s=$argn;$c=$s[$i++];$p=$c)$c!=$p||die;echo$i%2<1&&preg_match("#^(nu|mw|bq)#",count_chars($s,3));
```
Empty output for falsy. Run as pipe with `-nR`.
[Answer]
# Java 8, 57 bytes
```
s->s.matches("(nu)+n|(un)+u|(mw)+m|(wm)+w|(bq)+b|(qb)+q")
```
[Try it here.](https://tio.run/##jZJBbsMgEEX3OcXIKxCKLxClUg/QeBEpm6qRgNDWqRnbgTGqap/dpY1TdRXQhwWap88fhrMc5LrtDJ5PH7NupHPwJGv8WgHU6M3lVWoDu58jgGrbxkgEzfb@UuMbOL6JhSnuuJyXvtawA4QtzG794EorvX43jhUMiQscGSEXNDIbuLAjC5aLMDLVc6FG1isu@oLPm6tdR6qJdovr0NYnsDHYcvXzC0h@TbX/dN7YsiVfdrHkG2RYalYgYcF/A95lMqhgQ5JR/Z@SLOGie2SspKMnPG7pM3ocjlFJ6vEQlaSqqsp5@Rgsc0ZAmWDOpBCJbjsNh0VJ0mZ9NvrXybSa5m8)
Simple regex to match all six cases. Note that Java's [`String#matches`](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#matches(java.lang.String)) automatically matches the entire String, so there is no need for `^...$`.
[Answer]
# [MATL](https://github.com/lmendo/MATL), 25 bytes
```
'nuwmbq'&mq2&\d~wdts~Gnqv
```
The ouput is a non-empty numeric column vector, which is [truthy](https://codegolf.stackexchange.com/a/95057/36398) if all its entries are nonzero, and [falsy](https://codegolf.stackexchange.com/a/95057/36398) otherwise. [**Try it online!**](https://tio.run/##y00syfn/Xz2vtDw3qVBdLbfQSC0mpa48paS4zj2vsAwslacOAA "MATL – Try It Online")
To [**verify all test cases**](https://tio.run/##XVBNT8MwDL3nV/jCAhLqgT@AEEWICWkcEOIAiLZpqKXUSZtkpQf214fbbmshT/HzR54ju86C2X@@ruFwziC1SZJ0FZoygVvresDaGSwwAJKLAYKFwqDLbdYqWMM5kg9lpsBquL/YS4pdnTdyVTdXqze161TwuzU12/01wPzJgxYytDFUvRzjp@gr8KFF@oJjQfwsFXfGl0LqzPhR8l8zFcT7HwkpQC3SZS5F70zWi@dl8tFaB4UlhQEtgbYtz6qRMJSgTusAw88uh/lda4vSe6Dy@7CVYW6SYrAzM9jt6m6yYyFvTuBo@8FgvnlhMG82G7ZxoWZi6akpzP2nvkQxHu8QdgewX8tf), an `if` branch is added in the footer that replaces any truthy value by the string `'truthy'`, or any falsy value by the string `'falsy'`, and then displays the string.
### Explanation
```
'nuwmbq'  % Push this string
&m        % Implicit input. For each char, push index of membership in the above
          %  string, or 0 if not member
q         % Subtract 1
2         % Push 2
&\        % Divmod. Pushes remainders, then quotients
d~        % Consecutive differences negated. Gives an array of ones iff all
          % quotients were equal
w         % Swap. Moves remainders to top
d         % Consecutive differences. Gives nonzeros iff no consecutive
          % remainders were equal
ts~       % Duplicate, sum, negate. Gives true iff sum was 0. For unequal
          % consecutive differences of remainders, this corresponds to an odd
          % number of remainders
Gnq       % Push input, length, subtract 1. True iff input longer than 1
v         % Concatenate into column vector. Truthy iff all entries are nonzero
```
[Answer]
# [Python 2](https://docs.python.org/2/), 74 bytes
```
import re
re.compile('(n(un)+|u(nu)+|m(wm)+|w(mw)+|b(pb)+|p(bp)+)$').match
```
[Try it online!](https://tio.run/##pYxNCsMgEEb3cwoXhYwUsugykEVPkE3psiUGQ4RqVLSTQu9uJyHkAvWBb5ifz3/SNLtLKcb6OSYRNURdD7P15qWxQofZyfM3o8ssi2RZhJZYCoNiBVRBnuWpkrXt0zCVsf03AmjiW3GLWTcgljb29DTO54QShBnFiItsfDQuiaVc7wx0XQcuO5H5W4uNtSBLu7YJ7cD7wQABD9b@9kCFAziCIB95vPwD "Python 2 – Try It Online") This take on the problem is surprisingly competitive.
[Answer]
# Clojure, 115 bytes
```
(apply some-fn(map(fn[r]#(re-matches r %))(map(fn[[x y]](re-pattern(str x"("y x")+")))["nu""un""mw""wm""bq""qb"])))
```
Build a regex out of each letter pair and see if the input matches one. Lots of more elegant ways to do all of these parts, but they're all more verbose. Such is life with Clojure golfing.
[Answer]
# Perl 5, 68 + 1 = 69 bytes
```
if(/../&&$&=~/nu|un|bq|qb|mw|wm/){s/^($&)*//;$&=~/./;print if/^$&$/}
```
Run with `-n`.
Explanation:
```
# Match the first two characters, and if they exist, then...
if (/../ &&
 # Make sure they are a pair of compatible cartwheel characters.
 $&=~/nu|un|bq|qb|mw|wm/) {
  # If that's true, then eliminate as many of that pair of characters
  # from the beginning of the string as possible.
  s/^($&)*//;
  # Then get the first character out of the match (the first character
  # of the original string).
  $&=~/./;
  # Print the text (which is truthy since it's nonempty) if the original
  # first character matches exactly the remaining string.
  print if/^$&$/
  # Otherwise, print nothing (the empty string in Perl is falsy).
}
```
[Answer]
## [TXR Lisp](http://nongnu.org/txr), 50 bytes
```
(f^$ #/n(un)+|u(nu)+|m(wm)+|w(mw+)|b(qb)+|q(bq)+/)
```
Run:
```
1> (f^$ #/n(un)+|u(nu)+|m(wm)+|w(mw+)|b(qb)+|q(bq)+/)
#<intrinsic fun: 1 param>
2> [*1 "nun"]
"nun"
3> [*1 "nuns"]
nil
4> [*1 "mwm"]
"mwm"
5> [*1 "wmw"]
"wmw"
6> [*1 "abc"]
nil
```
`f^$` is a combinator which takes a regex object and returns a function which matches that regex in an anchored way. (By itself, a regex object is function-callable object which takes a string and searches for itself through it.)
[Answer]
# [Python 3](https://docs.python.org/3/), 66 bytes
```
lambda x:x==len(x)//2*x[:2]+x[0]and{*x}in[{*'nu'},{*'mw'},{*'bq'}]
```
[Try it online!](https://tio.run/##bZDBa4MwFMbv@ytyS3UpHe4mWNhlVy9llywDRaVCfG1NMjPEv929RdcmpXyE5Pu9L3mPnH/08QSvc5N9zrLoyqogNrVZJmvY2Gi3S2LL00Q8W/4iCqjG2E4t8DGmYOjEcO@GZS8vdBKzrpVWGedYBsrIoTe1YMTZBwCF7L2QaoEDPuZl0LpLt0B5WeXHvr9QQeztAxWQPM8Db7z@/kzYEu56oifmAVyG9RAY87/CwrAqoN3Viafm1JO/n2N9rYzUpAVnVXruW9AbV6LbPWWNO0fR/As "Python 3 – Try It Online")
[Answer]
## [TXR](http://nongnu.org/txr): ~~78~~ 74 bytes
```
@{x 2}@(rep :gap 0)@x@(end)@y
@(bind(x y)(#"nu un mw wm bq qb"@[x 0..1]))
```
Run, from system prompt. Number in prompt is termination status: 0 = success, 1 = failure:
```
0:$ ./txr cart.txr 
nun
0:$ ./txr cart.txr 
abc
1:$ ./txr cart.txr 
bab
1:$ ./txr cart.txr 
mwm
1:$ ./txr cart.txr 
nununununun
0:$
```
Explanation:
* `@{x 2}`: match two characters, bind to `x` variable.
* `@(rep :gap 0)@x@(end)`: repeated match with no skipped gaps: zero or more occurrences of `x`, the previously matched digraph.
* `@y`: remainder of line matched, captured into `y`.
* `@(bind(x y)(foo bar))`: bind `x` to `foo`, y to `bar`. Since `x` and `y` are already bound, they have to match `foo` and `bar`, or else there is a failure.
* `foo` is `#"nu un mw wm bq qb"`, a word list literal, syntactic sugar for the Lisp list `("nu" "un" ... "qb")`. A `bind` match between a variable and a list means that the variable must match an element.
* `bar` is `@[x 0..1]`: the one-character substring of `x` from its beginning. The `bind` match between `y` and this forces the last letter of the line to match the first.
[Answer]
## C++, 268 bytes
```
#include<map>
#include<string>
std::map<char,char>c{{'n','u'},{'m','w'},{98,'q'},{'w','m'},{'u','n'},{'q',98}};
int w(std::string s){if(s[0]!=s[s.size()-1]||c.find(s[0])==c.end()||s.size()<3)return 0;for(int i=0;i<s.size()-1;i+=2)if(s[i+1]!=c[s[i]])return 0;return 1;}
```
[Answer]
# JavaScript (ES6), 63 bytes
```
s=>/bq|wm|un/.test(s)&s.replace(RegExp(s[0]+s[1],'g'),'')==s[0]
```
Returns `1` or `0`.
**Explanation**
All cartwheel strings will have one or more of **bq**, **wm**, or **un**. We test for that with:
```
/bq|wm|un/.test(s)
```
If you replace all instances of the first two letters of a cartwheel string with nothing, you're left with the first letter of the string. We test for that with:
```
s.replace(RegExp(s[0]+s[1],'g'),'')==s[0]
```
```
let f=
s=>/bq|wm|un/.test(s)&s.replace(RegExp(s[0]+s[1],'g'),'')==s[0]
console.log(f('nun'))          // truthy
console.log(f('nunun'))        // truthy
console.log(f('nunununu'))     // falsy
console.log(f('wmw'))          // truthy
console.log(f('wmwun'))        // falsy
console.log(f('bqbqbqbqbqb'))  // truthy
console.log(f('v^v^v'))        // falsy
console.log(f('AVAVA'))        // falsy
console.log(f('OOO'))          // falsy
console.log(f('ununununu'))    // truthy
console.log(f('nunwmwnun'))    // falsy
console.log(f('nun unun'))     // falsy
console.log(f('nunwmw'))       // falsy
console.log(f('nnuunnuunnuu')) // falsy
console.log(f('nwnwnwnwn'))    // falsy
console.log(f('m'))            // falsy
```
]