[Question]
  [
This task is about compressing and processing a sequence of conditionals.
---
In the game [Keep Talking and Nobody Explodes](http://www.keeptalkinggame.com/), a bomb defuser must disarm a bomb with the help of instructions relayed by experts consulting a convoluted [Bomb Defusal Manual](http://www.bombmanual.com/manual/1/pdf/Bomb-Defusal-Manual_1.pdf). This challenge deals with the module "On the Subject of Wires", explained on page 5 of the manual. The defuser is presented with an array of colored wires. Only one of them is safe to cut -- the rest detonate the bomb. 
Your code acts as the expert to determine which wire to cut based on the number and colors of the wires, as per the instructions in the manual reproduced under "Wire cutting rules".
**Input:** An ordered list or string of 3, 4, 5, or 6 wire colors, represented by uppercase letters:
* `B`: Black
* `U`: Blue
* `R`: Red
* `W`: White
* `Y`: Yellow
Note that blue is `U`, not `B`. 
The input also includes a bit (True/False or 0/1) for whether the last digit of the bomb's serial number is odd, a condition used in some rules. 
You should not take the number of wires as a separate input, but derive it from the list or string of colors. You may have your list or string have a terminator element after the colors, perhaps if your language cannot tell how long it is. This terminator should be a fixed value that doesn't encode additional information.
**Output:** A number 1 through 6, indicating which wire to cut. This may not be zero-indexed.
**Wire cutting rules:** These rules are reproduced from page 5 of [the defusal manual](http://www.bombmanual.com/manual/1/pdf/Bomb-Defusal-Manual_1.pdf)
```
3 wires:
  If there are no red wires, cut the second wire.
  Otherwise, if the last wire is white, cut the last wire.
  Otherwise, if there is more than one blue wire, cut the last blue wire.
  Otherwise, cut the last wire.
4 wires:
  If there is more than one red wire and the last digit of the serial number is odd, cut the last red wire.
  Otherwise, if the last wire is yellow and there are no red wires, cut the first wire.
  Otherwise, if there is exactly one blue wire, cut the first wire.
  Otherwise, if there is more than one yellow wire, cut the last wire.
  Otherwise, cut the second wire.
5 wires:
  If the last wire is black and the last digit of the serial number is odd, cut the fourth wire.
  Otherwise, if there is exactly one red wire and there is more than one yellow wire, cut the first wire.
  Otherwise, if there are no black wires, cut the second wire.
  Otherwise, cut the first wire.
6 wires:
  If there are no yellow wires and the last digit of the serial number is odd, cut the third wire.
  Otherwise, if there is exactly one yellow wire and there is more than one white wire, cut the fourth wire.
  Otherwise, if there are no red wires, cut the last wire.
  Otherwise, cut the fourth wire.
```
**Reference solution ([TIO](https://tio.run/##pVtRb@M2En7e/ApeDos4PTeoY9UPC2SBU9E@FShAlDcYLBaBGyuxD44VKHK3@@u3lCw7IvXNUEaDRTaxPg6HM@TMN0Pl5Wu9Lne3376tikfzZVMV93V5/7CvJ83Pr1PzWlSb5fa@XK2uP1wY/3V5eWmLel/tTL0uzGa3Kv4y5WP7SzPE1KXxw6em3BXft0@L1Y35fb15Nf7f0uz2z38UlZk1uMVNK7Gd6YP5r9luXutG1txLq8r909oszEO5LSvzsF5Wy4e6qF7NY1U@m9xZ4nbwm36NhLwst8VyZx79mC/rwitVtZptl17yavO0qY@6HsY1OvmhXsFqX5hnP/Tw@0Ur@@PHj4FJPl3Zq6m5yptv7U909XnaDu1sMz9aqP3fL/W@XZu5M9tid7Dodfuo0ad95h@1H3/6fvb5MOnmsT/wzswPortH7cc3D@V@V0@8DtcN4oc3RPNVHbxze/qw2PqBvRnvGsXhmNPE4dhgUucn/Whm4fh/m18bC/@x3R92ARJ@dXXz/3JzNMNN1W6Og7z/mFlvxtciodzFSbPAUpluKa@0We5W/R2D1lAVq3OXYAdLGBicr9q5x7tvlnCBHzg7eyAj3ym@FzxxK3ngx8ADoQXyK9X6nehM0b6z12xoSW1dmj3ysQdIMMRMMsRC3orczTnGGvOEL7E1SLHGCPv@8E@3R3a0Sv95tdy8FuZ/Sx8hfq6qsppcUlXuno75oDzqcnl9cbF5fimr2mx8vK99QPcHvklOT8WuqJZ1cb/cbu83u5d9/Trp4m6bJJow@@kQnF0vQk@bw9fF1iYtvPlpszOf5lOTTc2PU7P4/KZrmz2OkJMWNy9Vudo/1JPDbFO/3JdiWd@dBF6H1mikvPm3ne2XpbfJIWN8DsHN19dNsV2ZSZMFuwgTpN9vdfX1w8W7L@vNtmi8@@5dXfgD9rBsRNbL6qmovQVaw0yu/VMvYL@tuwRzTGHfnc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3Mi9ydLNAmsvDOdp3sZq@kgLtum3ifM0h2WQ9UeorHAKjKVzsS6tcRRnc00wpckjg/aK/so2opCkgt05YKtcQ2CwU4s3hi/xpV44R00IEC8GjdsokWGsVdvCgzfJUUZfyFjSgiGnXuHFYOEVrgW8Hs/V3g2@Sx8ckb8B))**
This code is in Python.
```
def wire_to_cut(wires, serial_odd):
    """Return the index of the wire to cut, one-indexed. This is a number 1 to 6.
    wires: A list of 3 through 6 color characters from BURWY
    serial_odd: A Boolean for whether the last digit of the serial is odd.
    >>> wire_to_cut(['R', 'B', 'R', 'W'], True):
    3
    """
    num_wires = len(wires)
    last_wire = wires[-1]
    if num_wires == 3:
        if wires.count('R') == 0:
            return 2
        elif last_wire == 'W':
            return num_wires
        elif wires.count('U') > 1:
            # Last blue wire
            return ''.join(wires).rindex('U') + 1
        else:
            return num_wires
    elif num_wires == 4:
        if wires.count('R') > 1 and serial_odd:
            # Last red wire
            return ''.join(wires).rindex('R') + 1
        elif last_wire == 'Y' and wires.count('R') == 0:
            return 1
        elif wires.count('U') == 1:
            return 1
        elif wires.count('Y') > 1:
            return num_wires
        else:
            return 2
    elif num_wires == 5:
        if last_wire == 'B' and serial_odd:
            return 4
        elif wires.count('R') == 1 and wires.count('Y') > 1:
            return 1
        elif wires.count('B') == 0:
            return 2
        else:
            return 1
    elif num_wires == 6:
        if wires.count('Y') == 0 and serial_odd:
            return 3
        elif wires.count('Y') == 1 and wires.count('W') > 1:
            return 4
        elif wires.count('R') == 0:
            return num_wires
        else:
            return 4
    else:
        raise ValueError("Wrong number of wires.")
```
**Test cases**
As `(input, output)` where `input = (wires, odd_serial)`.
```
((['B', 'B', 'B'], False), 2)
((['B', 'B', 'Y'], True), 2)
((['B', 'R', 'R'], False), 3)
((['B', 'W', 'U'], True), 2)
((['U', 'B', 'B'], True), 2)
((['U', 'B', 'Y'], False), 2)
((['U', 'U', 'R'], True), 2)
((['U', 'U', 'U'], False), 2)
((['U', 'R', 'R'], True), 3)
((['U', 'Y', 'Y'], False), 2)
((['R', 'B', 'U'], False), 3)
((['R', 'B', 'Y'], False), 3)
((['R', 'U', 'B'], False), 3)
((['R', 'R', 'U'], False), 3)
((['R', 'W', 'U'], True), 3)
((['W', 'B', 'W'], False), 2)
((['W', 'B', 'Y'], True), 2)
((['W', 'R', 'U'], True), 3)
((['W', 'W', 'B'], True), 2)
((['W', 'W', 'U'], True), 2)
((['W', 'Y', 'W'], True), 2)
((['Y', 'U', 'B'], True), 2)
((['Y', 'U', 'W'], False), 2)
((['Y', 'R', 'U'], False), 3)
((['Y', 'Y', 'B'], False), 2)
((['Y', 'Y', 'B'], True), 2)
((['B', 'B', 'U', 'U'], True), 2)
((['B', 'B', 'R', 'W'], True), 2)
((['B', 'B', 'R', 'Y'], True), 2)
((['B', 'U', 'B', 'R'], False), 1)
((['B', 'U', 'R', 'W'], False), 1)
((['B', 'U', 'W', 'R'], True), 1)
((['B', 'U', 'W', 'Y'], True), 1)
((['B', 'U', 'Y', 'R'], False), 1)
((['B', 'R', 'U', 'B'], True), 1)
((['B', 'R', 'R', 'B'], True), 3)
((['B', 'R', 'Y', 'W'], True), 2)
((['B', 'R', 'Y', 'Y'], True), 4)
((['B', 'W', 'R', 'U'], True), 1)
((['B', 'W', 'Y', 'B'], False), 2)
((['B', 'Y', 'R', 'U'], False), 1)
((['B', 'Y', 'R', 'R'], False), 2)
((['U', 'B', 'R', 'W'], False), 1)
((['U', 'B', 'W', 'Y'], False), 1)
((['U', 'B', 'Y', 'W'], True), 1)
((['U', 'U', 'R', 'W'], True), 2)
((['U', 'U', 'W', 'B'], False), 2)
((['U', 'U', 'W', 'Y'], False), 1)
((['U', 'R', 'B', 'U'], False), 2)
((['U', 'R', 'Y', 'U'], True), 2)
((['U', 'R', 'Y', 'W'], False), 1)
((['U', 'R', 'Y', 'Y'], False), 1)
((['U', 'W', 'U', 'Y'], False), 1)
((['U', 'W', 'W', 'W'], False), 1)
((['U', 'Y', 'B', 'B'], False), 1)
((['U', 'Y', 'B', 'W'], True), 1)
((['U', 'Y', 'U', 'R'], True), 2)
((['U', 'Y', 'R', 'W'], False), 1)
((['R', 'B', 'R', 'R'], False), 2)
((['R', 'U', 'B', 'B'], True), 1)
((['R', 'U', 'W', 'B'], False), 1)
((['R', 'R', 'B', 'R'], True), 4)
((['R', 'R', 'W', 'R'], True), 4)
((['R', 'R', 'W', 'W'], True), 2)
((['R', 'R', 'Y', 'Y'], False), 4)
((['R', 'R', 'Y', 'Y'], True), 2)
((['R', 'W', 'U', 'W'], True), 1)
((['R', 'W', 'W', 'U'], False), 1)
((['R', 'W', 'Y', 'W'], False), 2)
((['R', 'Y', 'R', 'U'], False), 1)
((['R', 'Y', 'Y', 'W'], False), 4)
((['W', 'B', 'U', 'R'], False), 1)
((['W', 'B', 'U', 'Y'], False), 1)
((['W', 'U', 'B', 'Y'], False), 1)
((['W', 'U', 'U', 'W'], True), 2)
((['W', 'U', 'R', 'W'], False), 1)
((['W', 'W', 'R', 'U'], False), 1)
((['W', 'Y', 'R', 'R'], False), 2)
((['W', 'Y', 'Y', 'U'], False), 1)
((['W', 'Y', 'Y', 'Y'], True), 1)
((['Y', 'B', 'B', 'R'], True), 2)
((['Y', 'B', 'W', 'U'], False), 1)
((['Y', 'B', 'W', 'W'], False), 2)
((['Y', 'U', 'R', 'Y'], False), 1)
((['Y', 'R', 'B', 'R'], False), 2)
((['Y', 'R', 'U', 'R'], True), 4)
((['Y', 'R', 'R', 'Y'], False), 4)
((['Y', 'R', 'W', 'U'], False), 1)
((['Y', 'R', 'Y', 'B'], False), 4)
((['Y', 'R', 'Y', 'B'], True), 4)
((['Y', 'W', 'U', 'B'], False), 1)
((['Y', 'W', 'R', 'R'], True), 4)
((['Y', 'W', 'W', 'R'], True), 2)
((['Y', 'W', 'W', 'Y'], True), 1)
((['Y', 'W', 'Y', 'U'], False), 1)
((['Y', 'Y', 'B', 'B'], True), 4)
((['Y', 'Y', 'R', 'R'], True), 4)
((['B', 'B', 'B', 'R', 'W'], False), 1)
((['B', 'B', 'R', 'R', 'W'], False), 1)
((['B', 'U', 'B', 'W', 'U'], True), 1)
((['B', 'R', 'R', 'U', 'R'], True), 1)
((['B', 'R', 'R', 'W', 'W'], False), 1)
((['B', 'R', 'Y', 'Y', 'R'], False), 1)
((['B', 'W', 'B', 'W', 'B'], False), 1)
((['B', 'W', 'U', 'B', 'U'], True), 1)
((['B', 'W', 'R', 'U', 'W'], True), 1)
((['B', 'W', 'R', 'W', 'B'], False), 1)
((['B', 'W', 'W', 'R', 'U'], False), 1)
((['B', 'W', 'W', 'R', 'U'], True), 1)
((['B', 'W', 'W', 'W', 'B'], False), 1)
((['B', 'W', 'Y', 'R', 'Y'], True), 1)
((['B', 'Y', 'B', 'W', 'U'], True), 1)
((['B', 'Y', 'U', 'W', 'B'], True), 4)
((['B', 'Y', 'U', 'Y', 'W'], False), 1)
((['U', 'B', 'R', 'W', 'Y'], False), 1)
((['U', 'B', 'W', 'B', 'R'], False), 1)
((['U', 'B', 'W', 'B', 'W'], False), 1)
((['U', 'B', 'W', 'Y', 'R'], False), 1)
((['U', 'B', 'Y', 'U', 'B'], True), 4)
((['U', 'B', 'Y', 'U', 'Y'], False), 1)
((['U', 'B', 'Y', 'R', 'W'], False), 1)
((['U', 'U', 'B', 'B', 'U'], True), 1)
((['U', 'U', 'R', 'U', 'W'], True), 2)
((['U', 'U', 'Y', 'U', 'R'], True), 2)
((['U', 'U', 'Y', 'U', 'W'], False), 2)
((['U', 'R', 'B', 'Y', 'Y'], False), 1)
((['U', 'R', 'U', 'B', 'Y'], False), 1)
((['U', 'R', 'W', 'W', 'B'], False), 1)
((['U', 'R', 'Y', 'Y', 'W'], False), 1)
((['U', 'W', 'B', 'U', 'B'], True), 4)
((['U', 'W', 'U', 'U', 'B'], True), 4)
((['U', 'W', 'R', 'U', 'Y'], True), 2)
((['U', 'W', 'R', 'R', 'R'], True), 2)
((['U', 'W', 'R', 'R', 'W'], False), 2)
((['U', 'W', 'R', 'Y', 'W'], True), 2)
((['U', 'W', 'W', 'Y', 'R'], True), 2)
((['U', 'Y', 'B', 'W', 'Y'], False), 1)
((['U', 'Y', 'U', 'R', 'W'], True), 2)
((['U', 'Y', 'R', 'R', 'U'], False), 2)
((['U', 'Y', 'Y', 'B', 'W'], False), 1)
((['U', 'Y', 'Y', 'R', 'B'], True), 4)
((['U', 'Y', 'Y', 'Y', 'R'], False), 1)
((['R', 'B', 'B', 'W', 'U'], False), 1)
((['R', 'B', 'U', 'B', 'Y'], False), 1)
((['R', 'B', 'R', 'R', 'Y'], True), 1)
((['R', 'B', 'W', 'W', 'R'], True), 1)
((['R', 'B', 'W', 'W', 'W'], False), 1)
((['R', 'U', 'U', 'B', 'U'], True), 1)
((['R', 'U', 'U', 'R', 'Y'], False), 2)
((['R', 'U', 'R', 'B', 'W'], False), 1)
((['R', 'U', 'R', 'Y', 'R'], True), 2)
((['R', 'R', 'B', 'U', 'U'], True), 1)
((['R', 'R', 'B', 'R', 'W'], True), 1)
((['R', 'R', 'W', 'B', 'Y'], True), 1)
((['R', 'R', 'Y', 'Y', 'B'], False), 1)
((['R', 'W', 'U', 'Y', 'W'], False), 2)
((['R', 'W', 'Y', 'B', 'U'], True), 1)
((['R', 'Y', 'B', 'U', 'U'], True), 1)
((['R', 'Y', 'B', 'R', 'Y'], True), 1)
((['R', 'Y', 'B', 'W', 'R'], True), 1)
((['R', 'Y', 'R', 'U', 'U'], False), 2)
((['R', 'Y', 'Y', 'W', 'B'], True), 4)
((['R', 'Y', 'Y', 'W', 'W'], True), 1)
((['W', 'B', 'R', 'R', 'R'], False), 1)
((['W', 'U', 'U', 'U', 'B'], False), 1)
((['W', 'U', 'U', 'R', 'B'], False), 1)
((['W', 'U', 'R', 'B', 'R'], False), 1)
((['W', 'U', 'W', 'W', 'R'], True), 2)
((['W', 'U', 'Y', 'R', 'W'], True), 2)
((['W', 'R', 'R', 'B', 'Y'], True), 1)
((['W', 'W', 'U', 'B', 'W'], True), 1)
((['W', 'W', 'U', 'W', 'R'], False), 2)
((['W', 'W', 'W', 'W', 'B'], False), 1)
((['W', 'W', 'W', 'W', 'W'], False), 2)
((['W', 'W', 'Y', 'W', 'U'], True), 2)
((['W', 'W', 'Y', 'Y', 'R'], False), 1)
((['W', 'Y', 'R', 'B', 'B'], False), 1)
((['W', 'Y', 'W', 'B', 'W'], True), 1)
((['W', 'Y', 'Y', 'W', 'U'], True), 2)
((['Y', 'B', 'U', 'R', 'B'], True), 4)
((['Y', 'B', 'U', 'Y', 'R'], False), 1)
((['Y', 'B', 'R', 'Y', 'Y'], False), 1)
((['Y', 'B', 'W', 'U', 'B'], True), 4)
((['Y', 'B', 'Y', 'R', 'R'], False), 1)
((['Y', 'U', 'U', 'U', 'U'], False), 2)
((['Y', 'U', 'R', 'W', 'B'], False), 1)
((['Y', 'U', 'W', 'U', 'Y'], True), 2)
((['Y', 'U', 'Y', 'Y', 'W'], False), 2)
((['Y', 'R', 'R', 'R', 'Y'], False), 2)
((['Y', 'R', 'R', 'Y', 'R'], False), 2)
((['Y', 'R', 'W', 'W', 'U'], False), 2)
((['Y', 'W', 'B', 'R', 'U'], True), 1)
((['Y', 'W', 'U', 'U', 'W'], True), 2)
((['Y', 'W', 'U', 'R', 'B'], False), 1)
((['Y', 'W', 'R', 'R', 'R'], True), 2)
((['Y', 'W', 'R', 'Y', 'R'], False), 2)
((['Y', 'W', 'W', 'B', 'U'], True), 1)
((['Y', 'W', 'W', 'W', 'B'], False), 1)
((['Y', 'Y', 'R', 'Y', 'U'], False), 1)
((['B', 'B', 'B', 'B', 'R', 'U'], False), 4)
((['B', 'B', 'B', 'R', 'R', 'R'], True), 3)
((['B', 'B', 'R', 'U', 'W', 'Y'], False), 4)
((['B', 'B', 'R', 'R', 'R', 'B'], True), 3)
((['B', 'B', 'W', 'U', 'B', 'B'], False), 6)
((['B', 'B', 'W', 'U', 'B', 'U'], True), 3)
((['B', 'B', 'W', 'W', 'B', 'R'], True), 3)
((['B', 'B', 'Y', 'Y', 'W', 'R'], False), 4)
((['B', 'U', 'B', 'B', 'W', 'U'], False), 6)
((['B', 'U', 'U', 'W', 'W', 'Y'], True), 4)
((['B', 'U', 'U', 'Y', 'Y', 'R'], False), 4)
((['B', 'U', 'R', 'R', 'B', 'Y'], True), 4)
((['B', 'U', 'W', 'B', 'W', 'Y'], True), 4)
((['B', 'U', 'Y', 'R', 'R', 'R'], False), 4)
((['B', 'U', 'Y', 'R', 'Y', 'B'], False), 4)
((['B', 'R', 'U', 'B', 'U', 'B'], True), 3)
((['B', 'R', 'R', 'R', 'Y', 'B'], True), 4)
((['B', 'R', 'R', 'W', 'B', 'R'], True), 3)
((['B', 'R', 'Y', 'B', 'R', 'W'], False), 4)
((['B', 'R', 'Y', 'W', 'B', 'Y'], False), 4)
((['B', 'W', 'U', 'Y', 'U', 'W'], False), 4)
((['B', 'W', 'R', 'U', 'Y', 'Y'], True), 4)
((['B', 'W', 'R', 'Y', 'U', 'W'], False), 4)
((['B', 'W', 'W', 'Y', 'U', 'R'], False), 4)
((['B', 'W', 'Y', 'R', 'B', 'R'], False), 4)
((['B', 'W', 'Y', 'W', 'Y', 'U'], False), 6)
((['B', 'Y', 'B', 'R', 'B', 'R'], True), 4)
((['B', 'Y', 'U', 'B', 'Y', 'U'], False), 6)
((['B', 'Y', 'R', 'U', 'Y', 'U'], True), 4)
((['B', 'Y', 'R', 'R', 'W', 'W'], True), 4)
((['B', 'Y', 'W', 'W', 'U', 'B'], True), 4)
((['U', 'B', 'B', 'W', 'R', 'R'], True), 3)
((['U', 'B', 'W', 'B', 'W', 'U'], False), 6)
((['U', 'B', 'Y', 'U', 'B', 'R'], False), 4)
((['U', 'U', 'B', 'B', 'W', 'Y'], False), 6)
((['U', 'U', 'B', 'W', 'B', 'B'], True), 3)
((['U', 'U', 'B', 'Y', 'Y', 'Y'], False), 6)
((['U', 'U', 'U', 'B', 'U', 'Y'], True), 6)
((['U', 'U', 'U', 'B', 'Y', 'Y'], False), 6)
((['U', 'U', 'U', 'Y', 'W', 'B'], False), 6)
((['U', 'U', 'R', 'U', 'W', 'R'], True), 3)
((['U', 'U', 'Y', 'W', 'W', 'U'], True), 4)
((['U', 'U', 'Y', 'Y', 'B', 'R'], False), 4)
((['U', 'R', 'B', 'R', 'Y', 'R'], False), 4)
((['U', 'R', 'B', 'R', 'Y', 'Y'], True), 4)
((['U', 'R', 'R', 'B', 'U', 'R'], False), 4)
((['U', 'R', 'W', 'B', 'B', 'B'], False), 4)
((['U', 'R', 'W', 'Y', 'U', 'U'], True), 4)
((['U', 'R', 'Y', 'U', 'B', 'Y'], True), 4)
((['U', 'W', 'B', 'B', 'B', 'U'], False), 6)
((['U', 'W', 'B', 'R', 'W', 'Y'], True), 4)
((['U', 'W', 'R', 'R', 'B', 'R'], True), 3)
((['U', 'W', 'R', 'W', 'Y', 'B'], True), 4)
((['U', 'W', 'W', 'B', 'Y', 'R'], True), 4)
((['U', 'W', 'W', 'W', 'R', 'W'], False), 4)
((['U', 'W', 'W', 'W', 'R', 'Y'], True), 4)
((['U', 'Y', 'B', 'Y', 'R', 'W'], False), 4)
((['U', 'Y', 'U', 'R', 'U', 'Y'], False), 4)
((['U', 'Y', 'U', 'R', 'Y', 'W'], False), 4)
((['U', 'Y', 'R', 'W', 'U', 'U'], False), 4)
((['U', 'Y', 'R', 'Y', 'Y', 'U'], False), 4)
((['U', 'Y', 'Y', 'B', 'W', 'Y'], True), 6)
((['U', 'Y', 'Y', 'R', 'R', 'Y'], True), 4)
((['R', 'B', 'B', 'U', 'U', 'W'], False), 4)
((['R', 'B', 'B', 'Y', 'R', 'U'], False), 4)
((['R', 'B', 'R', 'Y', 'B', 'R'], True), 4)
((['R', 'B', 'W', 'B', 'R', 'B'], False), 4)
((['R', 'B', 'W', 'W', 'U', 'U'], True), 3)
((['R', 'B', 'Y', 'R', 'Y', 'W'], False), 4)
((['R', 'U', 'B', 'B', 'B', 'W'], True), 3)
((['R', 'U', 'B', 'B', 'R', 'W'], False), 4)
((['R', 'U', 'U', 'U', 'R', 'Y'], False), 4)
((['R', 'U', 'U', 'Y', 'U', 'W'], False), 4)
((['R', 'U', 'R', 'W', 'W', 'R'], False), 4)
((['R', 'U', 'R', 'W', 'W', 'W'], False), 4)
((['R', 'U', 'R', 'Y', 'R', 'U'], False), 4)
((['R', 'U', 'W', 'U', 'Y', 'W'], False), 4)
((['R', 'U', 'W', 'W', 'Y', 'Y'], True), 4)
((['R', 'U', 'W', 'Y', 'W', 'Y'], False), 4)
((['R', 'R', 'B', 'W', 'U', 'W'], False), 4)
((['R', 'R', 'B', 'W', 'W', 'U'], True), 3)
((['R', 'R', 'U', 'B', 'B', 'U'], False), 4)
((['R', 'R', 'U', 'W', 'R', 'B'], True), 3)
((['R', 'R', 'U', 'Y', 'Y', 'R'], False), 4)
((['R', 'R', 'W', 'U', 'W', 'W'], True), 3)
((['R', 'R', 'W', 'W', 'B', 'W'], False), 4)
((['R', 'R', 'Y', 'U', 'B', 'W'], False), 4)
((['R', 'R', 'Y', 'Y', 'U', 'Y'], True), 4)
((['R', 'W', 'B', 'Y', 'R', 'B'], True), 4)
((['R', 'W', 'U', 'B', 'U', 'R'], True), 3)
((['R', 'W', 'U', 'Y', 'U', 'Y'], False), 4)
((['R', 'W', 'W', 'U', 'B', 'Y'], True), 4)
((['R', 'W', 'Y', 'B', 'W', 'Y'], False), 4)
((['R', 'W', 'Y', 'U', 'B', 'Y'], False), 4)
((['R', 'W', 'Y', 'W', 'U', 'U'], False), 4)
((['R', 'Y', 'B', 'W', 'W', 'R'], False), 4)
((['R', 'Y', 'U', 'R', 'B', 'W'], False), 4)
((['R', 'Y', 'U', 'Y', 'R', 'U'], False), 4)
((['R', 'Y', 'R', 'R', 'U', 'R'], True), 4)
((['R', 'Y', 'Y', 'B', 'U', 'R'], False), 4)
((['R', 'Y', 'Y', 'B', 'R', 'W'], False), 4)
((['R', 'Y', 'Y', 'B', 'Y', 'R'], True), 4)
((['R', 'Y', 'Y', 'Y', 'Y', 'R'], False), 4)
((['W', 'B', 'B', 'B', 'R', 'U'], True), 3)
((['W', 'B', 'B', 'R', 'Y', 'Y'], False), 4)
((['W', 'B', 'B', 'Y', 'Y', 'R'], False), 4)
((['W', 'B', 'R', 'R', 'U', 'U'], True), 3)
((['W', 'B', 'R', 'W', 'R', 'Y'], False), 4)
((['W', 'B', 'Y', 'U', 'Y', 'Y'], True), 6)
((['W', 'B', 'Y', 'R', 'R', 'U'], False), 4)
((['W', 'U', 'U', 'B', 'R', 'W'], True), 3)
((['W', 'U', 'U', 'R', 'W', 'R'], False), 4)
((['W', 'U', 'R', 'U', 'B', 'W'], True), 3)
((['W', 'U', 'R', 'U', 'U', 'Y'], True), 4)
((['W', 'U', 'R', 'U', 'R', 'W'], True), 3)
((['W', 'U', 'R', 'U', 'R', 'Y'], False), 4)
((['W', 'U', 'R', 'R', 'U', 'R'], False), 4)
((['W', 'U', 'W', 'U', 'U', 'Y'], True), 4)
((['W', 'U', 'W', 'Y', 'B', 'R'], True), 4)
((['W', 'U', 'Y', 'R', 'B', 'W'], True), 4)
((['W', 'R', 'B', 'B', 'U', 'W'], False), 4)
((['W', 'R', 'B', 'B', 'U', 'Y'], True), 4)
((['W', 'R', 'B', 'Y', 'W', 'R'], False), 4)
((['W', 'R', 'U', 'B', 'W', 'B'], True), 3)
((['W', 'R', 'U', 'Y', 'Y', 'Y'], True), 4)
((['W', 'R', 'R', 'B', 'W', 'Y'], False), 4)
((['W', 'R', 'R', 'R', 'U', 'B'], False), 4)
((['W', 'R', 'R', 'W', 'W', 'Y'], True), 4)
((['W', 'R', 'W', 'B', 'B', 'W'], True), 3)
((['W', 'R', 'Y', 'U', 'B', 'B'], True), 4)
((['W', 'R', 'Y', 'R', 'R', 'R'], True), 4)
((['W', 'W', 'B', 'R', 'R', 'Y'], True), 4)
((['W', 'W', 'B', 'Y', 'U', 'U'], True), 4)
((['W', 'W', 'U', 'W', 'R', 'U'], True), 3)
((['W', 'W', 'U', 'W', 'Y', 'B'], True), 4)
((['W', 'W', 'U', 'Y', 'Y', 'B'], True), 6)
((['W', 'W', 'R', 'R', 'R', 'W'], True), 3)
((['W', 'W', 'W', 'U', 'W', 'Y'], False), 4)
((['W', 'Y', 'R', 'B', 'W', 'U'], False), 4)
((['W', 'Y', 'R', 'W', 'U', 'W'], True), 4)
((['W', 'Y', 'R', 'Y', 'R', 'B'], True), 4)
((['W', 'Y', 'W', 'U', 'U', 'B'], True), 4)
((['W', 'Y', 'Y', 'Y', 'R', 'B'], False), 4)
((['Y', 'B', 'B', 'R', 'W', 'R'], False), 4)
((['Y', 'B', 'R', 'R', 'U', 'B'], True), 4)
((['Y', 'B', 'R', 'Y', 'W', 'R'], False), 4)
((['Y', 'B', 'W', 'Y', 'B', 'R'], True), 4)
((['Y', 'B', 'Y', 'W', 'W', 'Y'], True), 6)
((['Y', 'U', 'B', 'U', 'B', 'U'], False), 6)
((['Y', 'U', 'B', 'U', 'U', 'U'], False), 6)
((['Y', 'U', 'B', 'U', 'Y', 'Y'], False), 6)
((['Y', 'U', 'B', 'W', 'R', 'Y'], True), 4)
((['Y', 'U', 'U', 'B', 'R', 'W'], False), 4)
((['Y', 'U', 'R', 'B', 'W', 'U'], False), 4)
((['Y', 'U', 'Y', 'R', 'Y', 'Y'], True), 4)
((['Y', 'R', 'B', 'B', 'U', 'R'], False), 4)
((['Y', 'R', 'B', 'B', 'U', 'W'], True), 4)
((['Y', 'R', 'B', 'B', 'R', 'B'], False), 4)
((['Y', 'R', 'B', 'R', 'B', 'W'], False), 4)
((['Y', 'R', 'U', 'U', 'U', 'R'], False), 4)
((['Y', 'R', 'R', 'U', 'B', 'W'], True), 4)
((['Y', 'R', 'R', 'W', 'B', 'W'], True), 4)
((['Y', 'R', 'R', 'W', 'U', 'W'], False), 4)
((['Y', 'R', 'W', 'B', 'Y', 'B'], True), 4)
((['Y', 'R', 'W', 'Y', 'Y', 'R'], False), 4)
((['Y', 'R', 'Y', 'B', 'Y', 'B'], False), 4)
((['Y', 'W', 'B', 'R', 'W', 'W'], False), 4)
((['Y', 'W', 'U', 'R', 'W', 'W'], False), 4)
((['Y', 'W', 'R', 'B', 'Y', 'U'], False), 4)
((['Y', 'W', 'R', 'U', 'U', 'Y'], False), 4)
((['Y', 'W', 'R', 'R', 'W', 'B'], True), 4)
((['Y', 'W', 'W', 'U', 'Y', 'W'], True), 6)
((['Y', 'W', 'Y', 'U', 'U', 'U'], True), 6)
((['Y', 'W', 'Y', 'R', 'B', 'B'], False), 4)
((['Y', 'Y', 'B', 'B', 'B', 'B'], True), 6)
((['Y', 'Y', 'B', 'B', 'W', 'R'], True), 4)
((['Y', 'Y', 'B', 'R', 'W', 'Y'], False), 4)
((['Y', 'Y', 'B', 'Y', 'Y', 'B'], False), 6)
((['Y', 'Y', 'R', 'B', 'Y', 'W'], False), 4)
((['Y', 'Y', 'R', 'Y', 'U', 'W'], True), 4)
```
This Python code generates all 39000 possible inputs ([TIO](https://tio.run/##pVtRb@M2En7e/ApeDos4PTeoY9UPC2SBU9E@FShAlDcYLBaBGyuxD44VKHK3@@u3lCw7IvXNUEaDRTaxPg6HM@TMN0Pl5Wu9Lne3376tikfzZVMV93V5/7CvJ83Pr1PzWlSb5fa@XK2uP1wY/3V5eWmLel/tTL0uzGa3Kv4y5WP7SzPE1KXxw6em3BXft0@L1Y35fb15Nf7f0uz2z38UlZk1uMVNK7Gd6YP5r9luXutG1txLq8r909oszEO5LSvzsF5Wy4e6qF7NY1U@m9xZ4nbwm36NhLwst8VyZx79mC/rwitVtZptl17yavO0qY@6HsY1OvmhXsFqX5hnP/Tw@0Ur@@PHj4FJPl3Zq6m5yptv7U909XnaDu1sMz9aqP3fL/W@XZu5M9tid7Dodfuo0ad95h@1H3/6fvb5MOnmsT/wzswPortH7cc3D@V@V0@8DtcN4oc3RPNVHbxze/qw2PqBvRnvGsXhmNPE4dhgUucn/Whm4fh/m18bC/@x3R92ARJ@dXXz/3JzNMNN1W6Og7z/mFlvxtciodzFSbPAUpluKa@0We5W/R2D1lAVq3OXYAdLGBicr9q5x7tvlnC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F6clK9YK4K1BjUVVYu8LBYKeWOBa2DrUtxNIlhwjW7hwweMSp5sT7BbjrrRMtC2lhUmVO8gsL7q3E80Rqv0d6azlPv11GIE2O0MKCKwhJCwsYkSiY5Tp5AbFW3RYEahErxCF0K0GqKdBVtip4kC8HuwJh7RlydRM76YCIYDpDY0pyJ3QDkwulOsWXDVqGFMGcFMxpP1tYVmN/oAypKmHT0ZtAl8xJlJNgJySlBSVZJEmZN9fkstxxzoZ/DJGqAFDpJhWy@OIt9QcZLllDEkjoA@wCvj1qk6cZKyI4mSGHTILxm8IYq9IgTBFSWPRGB3phM4cJRANb@Q8rMvkCcITgdGBjEE6kkpdha1zomiCwOwcsdt4YBDXp3LGaRpHd3Mi9ydLNAmsvDOdp3sZq@kgLtum3ifM0h2WQ9UeorHAKjKVzsS6tcRRnc00wpckjg/aK/so2opCkgt05YKtcQ2CwU4s3hi/xpV44R00IEC8GjdsokWGsVdvCgzfJUUZfyFjSgiGnXuHFYOEVrgW8Hs/V3g2@Sx8ckb8B)).
```
import itertools
def generate_all_inputs():
    colors = ['B', 'U', 'R', 'W', 'Y']
    for num_wires in [3, 4, 5, 6]:
        for wires in itertools.product(colors, repeat=num_wires):
            for serial_odd in [False, True]:
                yield (list(wires), serial_odd)
```
**Leaderboard**
```
var QUESTION_ID=125665,OVERRIDE_USER=20260;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/125665/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
```
```
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
```
```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
```
  
[Answer]
## JavaScript (ES6), ~~210~~ ~~203~~ ~~199~~ ~~187~~ 180 bytes
*Saved 7 bytes [thanks to nore](https://codegolf.stackexchange.com/questions/125665/which-wire-to-cut/125819#comment310352_125665).*
---
Takes the list of wires `w` and the flag `o` in currying syntax `(w)(o)`.
```
w=>o=>(([,,C,D,E,F]=w).map(c=>eval(c+`=${++i}+`+c),i=B=U=R=W=Y=''),F?!Y&o?3:7/Y&7&&W>7||R?4:6:E?E<'C'&o?4:7/R&7&&Y>7||B?1:2:D?R>7&o?+R[0]:D>'X'&!R|7/U&7?1:Y>7?4:2:!R?2:U<7?3:+U[0])
```
### How?
For each color, we build a string representing the list of 1-based indices at which this color is found, from last to first position.
For instance, the last test case `['Y', 'Y', 'R', 'Y', 'U', 'W']` will be translated as:
* **B = ''**
* **U = '5'**
* **R = '3'**
* **W = '6'**
* **Y = '421'**
These variables provide enough information to process all rules in a rather short format, except tests on specific wires which are performed on the destructured input list `[, , C, D, E, F]`.
```
Rule                              | Code
----------------------------------+---------------------------------------------------
no X wires                        | !X
more than one X wire              | X>7
exactly one X wire                | 7/X&7
position of last X wire (1-based) | +X[0]
(N+1)th wire is X (1-based)       | w[N]=='X' (where w[N] is replaced by C, D, E or F)
```
### Test cases
```
let f =
w=>o=>(([,,C,D,E,F]=w).map(c=>eval(c+`=${++i}+`+c),i=B=U=R=W=Y=''),F?!Y&o?3:7/Y&7&&W>7||R?4:6:E?E<'C'&o?4:7/R&7&&Y>7||B?1:2:D?R>7&o?+R[0]:D>'X'&!R|7/U&7?1:Y>7?4:2:!R?2:U<7?3:+U[0])
let passed = 0
let test = (a, r) => passed += (f(a[0])(a[1]) === r)
test([['B', 'B', 'B'], false], 2)
test([['B', 'B', 'Y'], true ], 2)
test([['B', 'R', 'R'], false], 3)
test([['B', 'W', 'U'], true ], 2)
test([['U', 'B', 'B'], true ], 2)
test([['U', 'B', 'Y'], false], 2)
test([['U', 'U', 'R'], true ], 2)
test([['U', 'U', 'U'], false], 2)
test([['U', 'R', 'R'], true ], 3)
test([['U', 'Y', 'Y'], false], 2)
test([['R', 'B', 'U'], false], 3)
test([['R', 'B', 'Y'], false], 3)
test([['R', 'U', 'B'], false], 3)
test([['R', 'R', 'U'], false], 3)
test([['R', 'W', 'U'], true ], 3)
test([['W', 'B', 'W'], false], 2)
test([['W', 'B', 'Y'], true ], 2)
test([['W', 'R', 'U'], true ], 3)
test([['W', 'W', 'B'], true ], 2)
test([['W', 'W', 'U'], true ], 2)
test([['W', 'Y', 'W'], true ], 2)
test([['Y', 'U', 'B'], true ], 2)
test([['Y', 'U', 'W'], false], 2)
test([['Y', 'R', 'U'], false], 3)
test([['Y', 'Y', 'B'], false], 2)
test([['Y', 'Y', 'B'], true ], 2)
test([['B', 'B', 'U', 'U'], true ], 2)
test([['B', 'B', 'R', 'W'], true ], 2)
test([['B', 'B', 'R', 'Y'], true ], 2)
test([['B', 'U', 'B', 'R'], false], 1)
test([['B', 'U', 'R', 'W'], false], 1)
test([['B', 'U', 'W', 'R'], true ], 1)
test([['B', 'U', 'W', 'Y'], true ], 1)
test([['B', 'U', 'Y', 'R'], false], 1)
test([['B', 'R', 'U', 'B'], true ], 1)
test([['B', 'R', 'R', 'B'], true ], 3)
test([['B', 'R', 'Y', 'W'], true ], 2)
test([['B', 'R', 'Y', 'Y'], true ], 4)
test([['B', 'W', 'R', 'U'], true ], 1)
test([['B', 'W', 'Y', 'B'], false], 2)
test([['B', 'Y', 'R', 'U'], false], 1)
test([['B', 'Y', 'R', 'R'], false], 2)
test([['U', 'B', 'R', 'W'], false], 1)
test([['U', 'B', 'W', 'Y'], false], 1)
test([['U', 'B', 'Y', 'W'], true ], 1)
test([['U', 'U', 'R', 'W'], true ], 2)
test([['U', 'U', 'W', 'B'], false], 2)
test([['U', 'U', 'W', 'Y'], false], 1)
test([['U', 'R', 'B', 'U'], false], 2)
test([['U', 'R', 'Y', 'U'], true ], 2)
test([['U', 'R', 'Y', 'W'], false], 1)
test([['U', 'R', 'Y', 'Y'], false], 1)
test([['U', 'W', 'U', 'Y'], false], 1)
test([['U', 'W', 'W', 'W'], false], 1)
test([['U', 'Y', 'B', 'B'], false], 1)
test([['U', 'Y', 'B', 'W'], true ], 1)
test([['U', 'Y', 'U', 'R'], true ], 2)
test([['U', 'Y', 'R', 'W'], false], 1)
test([['R', 'B', 'R', 'R'], false], 2)
test([['R', 'U', 'B', 'B'], true ], 1)
test([['R', 'U', 'W', 'B'], false], 1)
test([['R', 'R', 'B', 'R'], true ], 4)
test([['R', 'R', 'W', 'R'], true ], 4)
test([['R', 'R', 'W', 'W'], true ], 2)
test([['R', 'R', 'Y', 'Y'], false], 4)
test([['R', 'R', 'Y', 'Y'], true ], 2)
test([['R', 'W', 'U', 'W'], true ], 1)
test([['R', 'W', 'W', 'U'], false], 1)
test([['R', 'W', 'Y', 'W'], false], 2)
test([['R', 'Y', 'R', 'U'], false], 1)
test([['R', 'Y', 'Y', 'W'], false], 4)
test([['W', 'B', 'U', 'R'], false], 1)
test([['W', 'B', 'U', 'Y'], false], 1)
test([['W', 'U', 'B', 'Y'], false], 1)
test([['W', 'U', 'U', 'W'], true ], 2)
test([['W', 'U', 'R', 'W'], false], 1)
test([['W', 'W', 'R', 'U'], false], 1)
test([['W', 'Y', 'R', 'R'], false], 2)
test([['W', 'Y', 'Y', 'U'], false], 1)
test([['W', 'Y', 'Y', 'Y'], true ], 1)
test([['Y', 'B', 'B', 'R'], true ], 2)
test([['Y', 'B', 'W', 'U'], false], 1)
test([['Y', 'B', 'W', 'W'], false], 2)
test([['Y', 'U', 'R', 'Y'], false], 1)
test([['Y', 'R', 'B', 'R'], false], 2)
test([['Y', 'R', 'U', 'R'], true ], 4)
test([['Y', 'R', 'R', 'Y'], false], 4)
test([['Y', 'R', 'W', 'U'], false], 1)
test([['Y', 'R', 'Y', 'B'], false], 4)
test([['Y', 'R', 'Y', 'B'], true ], 4)
test([['Y', 'W', 'U', 'B'], false], 1)
test([['Y', 'W', 'R', 'R'], true ], 4)
test([['Y', 'W', 'W', 'R'], true ], 2)
test([['Y', 'W', 'W', 'Y'], true ], 1)
test([['Y', 'W', 'Y', 'U'], false], 1)
test([['Y', 'Y', 'B', 'B'], true ], 4)
test([['Y', 'Y', 'R', 'R'], true ], 4)
test([['B', 'B', 'B', 'R', 'W'], false], 1)
test([['B', 'B', 'R', 'R', 'W'], false], 1)
test([['B', 'U', 'B', 'W', 'U'], true ], 1)
test([['B', 'R', 'R', 'U', 'R'], true ], 1)
test([['B', 'R', 'R', 'W', 'W'], false], 1)
test([['B', 'R', 'Y', 'Y', 'R'], false], 1)
test([['B', 'W', 'B', 'W', 'B'], false], 1)
test([['B', 'W', 'U', 'B', 'U'], true ], 1)
test([['B', 'W', 'R', 'U', 'W'], true ], 1)
test([['B', 'W', 'R', 'W', 'B'], false], 1)
test([['B', 'W', 'W', 'R', 'U'], false], 1)
test([['B', 'W', 'W', 'R', 'U'], true ], 1)
test([['B', 'W', 'W', 'W', 'B'], false], 1)
test([['B', 'W', 'Y', 'R', 'Y'], true ], 1)
test([['B', 'Y', 'B', 'W', 'U'], true ], 1)
test([['B', 'Y', 'U', 'W', 'B'], true ], 4)
test([['B', 'Y', 'U', 'Y', 'W'], false], 1)
test([['U', 'B', 'R', 'W', 'Y'], false], 1)
test([['U', 'B', 'W', 'B', 'R'], false], 1)
test([['U', 'B', 'W', 'B', 'W'], false], 1)
test([['U', 'B', 'W', 'Y', 'R'], false], 1)
test([['U', 'B', 'Y', 'U', 'B'], true ], 4)
test([['U', 'B', 'Y', 'U', 'Y'], false], 1)
test([['U', 'B', 'Y', 'R', 'W'], false], 1)
test([['U', 'U', 'B', 'B', 'U'], true ], 1)
test([['U', 'U', 'R', 'U', 'W'], true ], 2)
test([['U', 'U', 'Y', 'U', 'R'], true ], 2)
test([['U', 'U', 'Y', 'U', 'W'], false], 2)
test([['U', 'R', 'B', 'Y', 'Y'], false], 1)
test([['U', 'R', 'U', 'B', 'Y'], false], 1)
test([['U', 'R', 'W', 'W', 'B'], false], 1)
test([['U', 'R', 'Y', 'Y', 'W'], false], 1)
test([['U', 'W', 'B', 'U', 'B'], true ], 4)
test([['U', 'W', 'U', 'U', 'B'], true ], 4)
test([['U', 'W', 'R', 'U', 'Y'], true ], 2)
test([['U', 'W', 'R', 'R', 'R'], true ], 2)
test([['U', 'W', 'R', 'R', 'W'], false], 2)
test([['U', 'W', 'R', 'Y', 'W'], true ], 2)
test([['U', 'W', 'W', 'Y', 'R'], true ], 2)
test([['U', 'Y', 'B', 'W', 'Y'], false], 1)
test([['U', 'Y', 'U', 'R', 'W'], true ], 2)
test([['U', 'Y', 'R', 'R', 'U'], false], 2)
test([['U', 'Y', 'Y', 'B', 'W'], false], 1)
test([['U', 'Y', 'Y', 'R', 'B'], true ], 4)
test([['U', 'Y', 'Y', 'Y', 'R'], false], 1)
test([['R', 'B', 'B', 'W', 'U'], false], 1)
test([['R', 'B', 'U', 'B', 'Y'], false], 1)
test([['R', 'B', 'R', 'R', 'Y'], true ], 1)
test([['R', 'B', 'W', 'W', 'R'], true ], 1)
test([['R', 'B', 'W', 'W', 'W'], false], 1)
test([['R', 'U', 'U', 'B', 'U'], true ], 1)
test([['R', 'U', 'U', 'R', 'Y'], false], 2)
test([['R', 'U', 'R', 'B', 'W'], false], 1)
test([['R', 'U', 'R', 'Y', 'R'], true ], 2)
test([['R', 'R', 'B', 'U', 'U'], true ], 1)
test([['R', 'R', 'B', 'R', 'W'], true ], 1)
test([['R', 'R', 'W', 'B', 'Y'], true ], 1)
test([['R', 'R', 'Y', 'Y', 'B'], false], 1)
test([['R', 'W', 'U', 'Y', 'W'], false], 2)
test([['R', 'W', 'Y', 'B', 'U'], true ], 1)
test([['R', 'Y', 'B', 'U', 'U'], true ], 1)
test([['R', 'Y', 'B', 'R', 'Y'], true ], 1)
test([['R', 'Y', 'B', 'W', 'R'], true ], 1)
test([['R', 'Y', 'R', 'U', 'U'], false], 2)
test([['R', 'Y', 'Y', 'W', 'B'], true ], 4)
test([['R', 'Y', 'Y', 'W', 'W'], true ], 1)
test([['W', 'B', 'R', 'R', 'R'], false], 1)
test([['W', 'U', 'U', 'U', 'B'], false], 1)
test([['W', 'U', 'U', 'R', 'B'], false], 1)
test([['W', 'U', 'R', 'B', 'R'], false], 1)
test([['W', 'U', 'W', 'W', 'R'], true ], 2)
test([['W', 'U', 'Y', 'R', 'W'], true ], 2)
test([['W', 'R', 'R', 'B', 'Y'], true ], 1)
test([['W', 'W', 'U', 'B', 'W'], true ], 1)
test([['W', 'W', 'U', 'W', 'R'], false], 2)
test([['W', 'W', 'W', 'W', 'B'], false], 1)
test([['W', 'W', 'W', 'W', 'W'], false], 2)
test([['W', 'W', 'Y', 'W', 'U'], true ], 2)
test([['W', 'W', 'Y', 'Y', 'R'], false], 1)
test([['W', 'Y', 'R', 'B', 'B'], false], 1)
test([['W', 'Y', 'W', 'B', 'W'], true ], 1)
test([['W', 'Y', 'Y', 'W', 'U'], true ], 2)
test([['Y', 'B', 'U', 'R', 'B'], true ], 4)
test([['Y', 'B', 'U', 'Y', 'R'], false], 1)
test([['Y', 'B', 'R', 'Y', 'Y'], false], 1)
test([['Y', 'B', 'W', 'U', 'B'], true ], 4)
test([['Y', 'B', 'Y', 'R', 'R'], false], 1)
test([['Y', 'U', 'U', 'U', 'U'], false], 2)
test([['Y', 'U', 'R', 'W', 'B'], false], 1)
test([['Y', 'U', 'W', 'U', 'Y'], true ], 2)
test([['Y', 'U', 'Y', 'Y', 'W'], false], 2)
test([['Y', 'R', 'R', 'R', 'Y'], false], 2)
test([['Y', 'R', 'R', 'Y', 'R'], false], 2)
test([['Y', 'R', 'W', 'W', 'U'], false], 2)
test([['Y', 'W', 'B', 'R', 'U'], true ], 1)
test([['Y', 'W', 'U', 'U', 'W'], true ], 2)
test([['Y', 'W', 'U', 'R', 'B'], false], 1)
test([['Y', 'W', 'R', 'R', 'R'], true ], 2)
test([['Y', 'W', 'R', 'Y', 'R'], false], 2)
test([['Y', 'W', 'W', 'B', 'U'], true ], 1)
test([['Y', 'W', 'W', 'W', 'B'], false], 1)
test([['Y', 'Y', 'R', 'Y', 'U'], false], 1)
test([['B', 'B', 'B', 'B', 'R', 'U'], false], 4)
test([['B', 'B', 'B', 'R', 'R', 'R'], true ], 3)
test([['B', 'B', 'R', 'U', 'W', 'Y'], false], 4)
test([['B', 'B', 'R', 'R', 'R', 'B'], true ], 3)
test([['B', 'B', 'W', 'U', 'B', 'B'], false], 6)
test([['B', 'B', 'W', 'U', 'B', 'U'], true ], 3)
test([['B', 'B', 'W', 'W', 'B', 'R'], true ], 3)
test([['B', 'B', 'Y', 'Y', 'W', 'R'], false], 4)
test([['B', 'U', 'B', 'B', 'W', 'U'], false], 6)
test([['B', 'U', 'U', 'W', 'W', 'Y'], true ], 4)
test([['B', 'U', 'U', 'Y', 'Y', 'R'], false], 4)
test([['B', 'U', 'R', 'R', 'B', 'Y'], true ], 4)
test([['B', 'U', 'W', 'B', 'W', 'Y'], true ], 4)
test([['B', 'U', 'Y', 'R', 'R', 'R'], false], 4)
test([['B', 'U', 'Y', 'R', 'Y', 'B'], false], 4)
test([['B', 'R', 'U', 'B', 'U', 'B'], true ], 3)
test([['B', 'R', 'R', 'R', 'Y', 'B'], true ], 4)
test([['B', 'R', 'R', 'W', 'B', 'R'], true ], 3)
test([['B', 'R', 'Y', 'B', 'R', 'W'], false], 4)
test([['B', 'R', 'Y', 'W', 'B', 'Y'], false], 4)
test([['B', 'W', 'U', 'Y', 'U', 'W'], false], 4)
test([['B', 'W', 'R', 'U', 'Y', 'Y'], true ], 4)
test([['B', 'W', 'R', 'Y', 'U', 'W'], false], 4)
test([['B', 'W', 'W', 'Y', 'U', 'R'], false], 4)
test([['B', 'W', 'Y', 'R', 'B', 'R'], false], 4)
test([['B', 'W', 'Y', 'W', 'Y', 'U'], false], 6)
test([['B', 'Y', 'B', 'R', 'B', 'R'], true ], 4)
test([['B', 'Y', 'U', 'B', 'Y', 'U'], false], 6)
test([['B', 'Y', 'R', 'U', 'Y', 'U'], true ], 4)
test([['B', 'Y', 'R', 'R', 'W', 'W'], true ], 4)
test([['B', 'Y', 'W', 'W', 'U', 'B'], true ], 4)
test([['U', 'B', 'B', 'W', 'R', 'R'], true ], 3)
test([['U', 'B', 'W', 'B', 'W', 'U'], false], 6)
test([['U', 'B', 'Y', 'U', 'B', 'R'], false], 4)
test([['U', 'U', 'B', 'B', 'W', 'Y'], false], 6)
test([['U', 'U', 'B', 'W', 'B', 'B'], true ], 3)
test([['U', 'U', 'B', 'Y', 'Y', 'Y'], false], 6)
test([['U', 'U', 'U', 'B', 'U', 'Y'], true ], 6)
test([['U', 'U', 'U', 'B', 'Y', 'Y'], false], 6)
test([['U', 'U', 'U', 'Y', 'W', 'B'], false], 6)
test([['U', 'U', 'R', 'U', 'W', 'R'], true ], 3)
test([['U', 'U', 'Y', 'W', 'W', 'U'], true ], 4)
test([['U', 'U', 'Y', 'Y', 'B', 'R'], false], 4)
test([['U', 'R', 'B', 'R', 'Y', 'R'], false], 4)
test([['U', 'R', 'B', 'R', 'Y', 'Y'], true ], 4)
test([['U', 'R', 'R', 'B', 'U', 'R'], false], 4)
test([['U', 'R', 'W', 'B', 'B', 'B'], false], 4)
test([['U', 'R', 'W', 'Y', 'U', 'U'], true ], 4)
test([['U', 'R', 'Y', 'U', 'B', 'Y'], true ], 4)
test([['U', 'W', 'B', 'B', 'B', 'U'], false], 6)
test([['U', 'W', 'B', 'R', 'W', 'Y'], true ], 4)
test([['U', 'W', 'R', 'R', 'B', 'R'], true ], 3)
test([['U', 'W', 'R', 'W', 'Y', 'B'], true ], 4)
test([['U', 'W', 'W', 'B', 'Y', 'R'], true ], 4)
test([['U', 'W', 'W', 'W', 'R', 'W'], false], 4)
test([['U', 'W', 'W', 'W', 'R', 'Y'], true ], 4)
test([['U', 'Y', 'B', 'Y', 'R', 'W'], false], 4)
test([['U', 'Y', 'U', 'R', 'U', 'Y'], false], 4)
test([['U', 'Y', 'U', 'R', 'Y', 'W'], false], 4)
test([['U', 'Y', 'R', 'W', 'U', 'U'], false], 4)
test([['U', 'Y', 'R', 'Y', 'Y', 'U'], false], 4)
test([['U', 'Y', 'Y', 'B', 'W', 'Y'], true ], 6)
test([['U', 'Y', 'Y', 'R', 'R', 'Y'], true ], 4)
test([['R', 'B', 'B', 'U', 'U', 'W'], false], 4)
test([['R', 'B', 'B', 'Y', 'R', 'U'], false], 4)
test([['R', 'B', 'R', 'Y', 'B', 'R'], true ], 4)
test([['R', 'B', 'W', 'B', 'R', 'B'], false], 4)
test([['R', 'B', 'W', 'W', 'U', 'U'], true ], 3)
test([['R', 'B', 'Y', 'R', 'Y', 'W'], false], 4)
test([['R', 'U', 'B', 'B', 'B', 'W'], true ], 3)
test([['R', 'U', 'B', 'B', 'R', 'W'], false], 4)
test([['R', 'U', 'U', 'U', 'R', 'Y'], false], 4)
test([['R', 'U', 'U', 'Y', 'U', 'W'], false], 4)
test([['R', 'U', 'R', 'W', 'W', 'R'], false], 4)
test([['R', 'U', 'R', 'W', 'W', 'W'], false], 4)
test([['R', 'U', 'R', 'Y', 'R', 'U'], false], 4)
test([['R', 'U', 'W', 'U', 'Y', 'W'], false], 4)
test([['R', 'U', 'W', 'W', 'Y', 'Y'], true ], 4)
test([['R', 'U', 'W', 'Y', 'W', 'Y'], false], 4)
test([['R', 'R', 'B', 'W', 'U', 'W'], false], 4)
test([['R', 'R', 'B', 'W', 'W', 'U'], true ], 3)
test([['R', 'R', 'U', 'B', 'B', 'U'], false], 4)
test([['R', 'R', 'U', 'W', 'R', 'B'], true ], 3)
test([['R', 'R', 'U', 'Y', 'Y', 'R'], false], 4)
test([['R', 'R', 'W', 'U', 'W', 'W'], true ], 3)
test([['R', 'R', 'W', 'W', 'B', 'W'], false], 4)
test([['R', 'R', 'Y', 'U', 'B', 'W'], false], 4)
test([['R', 'R', 'Y', 'Y', 'U', 'Y'], true ], 4)
test([['R', 'W', 'B', 'Y', 'R', 'B'], true ], 4)
test([['R', 'W', 'U', 'B', 'U', 'R'], true ], 3)
test([['R', 'W', 'U', 'Y', 'U', 'Y'], false], 4)
test([['R', 'W', 'W', 'U', 'B', 'Y'], true ], 4)
test([['R', 'W', 'Y', 'B', 'W', 'Y'], false], 4)
test([['R', 'W', 'Y', 'U', 'B', 'Y'], false], 4)
test([['R', 'W', 'Y', 'W', 'U', 'U'], false], 4)
test([['R', 'Y', 'B', 'W', 'W', 'R'], false], 4)
test([['R', 'Y', 'U', 'R', 'B', 'W'], false], 4)
test([['R', 'Y', 'U', 'Y', 'R', 'U'], false], 4)
test([['R', 'Y', 'R', 'R', 'U', 'R'], true ], 4)
test([['R', 'Y', 'Y', 'B', 'U', 'R'], false], 4)
test([['R', 'Y', 'Y', 'B', 'R', 'W'], false], 4)
test([['R', 'Y', 'Y', 'B', 'Y', 'R'], true ], 4)
test([['R', 'Y', 'Y', 'Y', 'Y', 'R'], false], 4)
test([['W', 'B', 'B', 'B', 'R', 'U'], true ], 3)
test([['W', 'B', 'B', 'R', 'Y', 'Y'], false], 4)
test([['W', 'B', 'B', 'Y', 'Y', 'R'], false], 4)
test([['W', 'B', 'R', 'R', 'U', 'U'], true ], 3)
test([['W', 'B', 'R', 'W', 'R', 'Y'], false], 4)
test([['W', 'B', 'Y', 'U', 'Y', 'Y'], true ], 6)
test([['W', 'B', 'Y', 'R', 'R', 'U'], false], 4)
test([['W', 'U', 'U', 'B', 'R', 'W'], true ], 3)
test([['W', 'U', 'U', 'R', 'W', 'R'], false], 4)
test([['W', 'U', 'R', 'U', 'B', 'W'], true ], 3)
test([['W', 'U', 'R', 'U', 'U', 'Y'], true ], 4)
test([['W', 'U', 'R', 'U', 'R', 'W'], true ], 3)
test([['W', 'U', 'R', 'U', 'R', 'Y'], false], 4)
test([['W', 'U', 'R', 'R', 'U', 'R'], false], 4)
test([['W', 'U', 'W', 'U', 'U', 'Y'], true ], 4)
test([['W', 'U', 'W', 'Y', 'B', 'R'], true ], 4)
test([['W', 'U', 'Y', 'R', 'B', 'W'], true ], 4)
test([['W', 'R', 'B', 'B', 'U', 'W'], false], 4)
test([['W', 'R', 'B', 'B', 'U', 'Y'], true ], 4)
test([['W', 'R', 'B', 'Y', 'W', 'R'], false], 4)
test([['W', 'R', 'U', 'B', 'W', 'B'], true ], 3)
test([['W', 'R', 'U', 'Y', 'Y', 'Y'], true ], 4)
test([['W', 'R', 'R', 'B', 'W', 'Y'], false], 4)
test([['W', 'R', 'R', 'R', 'U', 'B'], false], 4)
test([['W', 'R', 'R', 'W', 'W', 'Y'], true ], 4)
test([['W', 'R', 'W', 'B', 'B', 'W'], true ], 3)
test([['W', 'R', 'Y', 'U', 'B', 'B'], true ], 4)
test([['W', 'R', 'Y', 'R', 'R', 'R'], true ], 4)
test([['W', 'W', 'B', 'R', 'R', 'Y'], true ], 4)
test([['W', 'W', 'B', 'Y', 'U', 'U'], true ], 4)
test([['W', 'W', 'U', 'W', 'R', 'U'], true ], 3)
test([['W', 'W', 'U', 'W', 'Y', 'B'], true ], 4)
test([['W', 'W', 'U', 'Y', 'Y', 'B'], true ], 6)
test([['W', 'W', 'R', 'R', 'R', 'W'], true ], 3)
test([['W', 'W', 'W', 'U', 'W', 'Y'], false], 4)
test([['W', 'Y', 'R', 'B', 'W', 'U'], false], 4)
test([['W', 'Y', 'R', 'W', 'U', 'W'], true ], 4)
test([['W', 'Y', 'R', 'Y', 'R', 'B'], true ], 4)
test([['W', 'Y', 'W', 'U', 'U', 'B'], true ], 4)
test([['W', 'Y', 'Y', 'Y', 'R', 'B'], false], 4)
test([['Y', 'B', 'B', 'R', 'W', 'R'], false], 4)
test([['Y', 'B', 'R', 'R', 'U', 'B'], true ], 4)
test([['Y', 'B', 'R', 'Y', 'W', 'R'], false], 4)
test([['Y', 'B', 'W', 'Y', 'B', 'R'], true ], 4)
test([['Y', 'B', 'Y', 'W', 'W', 'Y'], true ], 6)
test([['Y', 'U', 'B', 'U', 'B', 'U'], false], 6)
test([['Y', 'U', 'B', 'U', 'U', 'U'], false], 6)
test([['Y', 'U', 'B', 'U', 'Y', 'Y'], false], 6)
test([['Y', 'U', 'B', 'W', 'R', 'Y'], true ], 4)
test([['Y', 'U', 'U', 'B', 'R', 'W'], false], 4)
test([['Y', 'U', 'R', 'B', 'W', 'U'], false], 4)
test([['Y', 'U', 'Y', 'R', 'Y', 'Y'], true ], 4)
test([['Y', 'R', 'B', 'B', 'U', 'R'], false], 4)
test([['Y', 'R', 'B', 'B', 'U', 'W'], true ], 4)
test([['Y', 'R', 'B', 'B', 'R', 'B'], false], 4)
test([['Y', 'R', 'B', 'R', 'B', 'W'], false], 4)
test([['Y', 'R', 'U', 'U', 'U', 'R'], false], 4)
test([['Y', 'R', 'R', 'U', 'B', 'W'], true ], 4)
test([['Y', 'R', 'R', 'W', 'B', 'W'], true ], 4)
test([['Y', 'R', 'R', 'W', 'U', 'W'], false], 4)
test([['Y', 'R', 'W', 'B', 'Y', 'B'], true ], 4)
test([['Y', 'R', 'W', 'Y', 'Y', 'R'], false], 4)
test([['Y', 'R', 'Y', 'B', 'Y', 'B'], false], 4)
test([['Y', 'W', 'B', 'R', 'W', 'W'], false], 4)
test([['Y', 'W', 'U', 'R', 'W', 'W'], false], 4)
test([['Y', 'W', 'R', 'B', 'Y', 'U'], false], 4)
test([['Y', 'W', 'R', 'U', 'U', 'Y'], false], 4)
test([['Y', 'W', 'R', 'R', 'W', 'B'], true ], 4)
test([['Y', 'W', 'W', 'U', 'Y', 'W'], true ], 6)
test([['Y', 'W', 'Y', 'U', 'U', 'U'], true ], 6)
test([['Y', 'W', 'Y', 'R', 'B', 'B'], false], 4)
test([['Y', 'Y', 'B', 'B', 'B', 'B'], true ], 6)
test([['Y', 'Y', 'B', 'B', 'W', 'R'], true ], 4)
test([['Y', 'Y', 'B', 'R', 'W', 'Y'], false], 4)
test([['Y', 'Y', 'B', 'Y', 'Y', 'B'], false], 6)
test([['Y', 'Y', 'R', 'B', 'Y', 'W'], false], 4)
test([['Y', 'Y', 'R', 'Y', 'U', 'W'], true ], 4)
console.log('Passed: ' + passed + '/379')
```
### All possible inputs
This should take one or two seconds to complete, mostly because *eval()* is slow.
```
const color = ['B', 'U', 'R', 'W', 'Y'];
let all = n => [...Array(5 ** n).keys()].map(c => [...Array(n).keys()].map(i => color[(c / 5 ** i | 0) % 5]))
let wire_to_cut = (wires, serial_odd) => {
    let num_wires = wires.length,
        last_wire = wires[num_wires - 1],
        wires_count = c => wires.reduce((s, x) => s += x == c, s = 0);
    if(num_wires == 3) {
        if(wires_count('R') == 0)
            return 2;
        else if(last_wire == 'W')
            return num_wires;
        else if(wires_count('U') > 1)
            // Last blue wire
            return wires.lastIndexOf('U') + 1;
        else
            return num_wires;
    }
    else if(num_wires == 4) {
        if(wires_count('R') > 1 && serial_odd)
            // Last red wire
            return wires.lastIndexOf('R') + 1;
        else if(last_wire == 'Y' && wires_count('R') == 0)
            return 1;
        else if(wires_count('U') == 1)
            return 1;
        else if(wires_count('Y') > 1)
            return num_wires;
        else
            return 2;
    }
    else if(num_wires == 5) {
        if(last_wire == 'B' && serial_odd)
            return 4;
        else if(wires_count('R') == 1 && wires_count('Y') > 1)
            return 1;
        else if(wires_count('B') == 0)
            return 2;
        else
            return 1;
    }
    else if(num_wires == 6) {
        if(wires_count('Y') == 0 && serial_odd)
            return 3;
        else if(wires_count('Y') == 1 && wires_count('W') > 1)
            return 4;
        else if(wires_count('R') == 0)
            return num_wires;
        else
            return 4;
    }
}
let f = w=>o=>(([,,C,D,E,F]=w).map(c=>eval(c+`=${++i}+`+c),i=B=U=R=W=Y=''),F?!Y&o?3:7/Y&7&&W>7||R?4:6:E?E<'C'&o?4:7/R&7&&Y>7||B?1:2:D?R>7&o?+R[0]:D>'X'&!R|7/U&7?1:Y>7?4:2:!R?2:U<7?3:+U[0])
for(let N = 3; N <= 6; N++) {
  let total = 0, passed = 0;
  
  all(N).forEach(l => {
    passed += f(l)(false) === wire_to_cut(l, false);
    passed += f(l)(true)  === wire_to_cut(l, true);
    total += 2;
  })
  console.log(N + ' wires: ' + passed + ' / ' + total);
}
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~300~~ 214 bytes
-12 bytes thanks to a [comment made by nore](https://codegolf.stackexchange.com/questions/125665/which-wire-to-cut?answertab=active#comment310352_125665) (for length 3 the last wire white test is redundant!)
```
def f(w,o):e=w[-1];r,u,y,x=map(w.count,'RUYW');g=r>0;return[2+(u<2or'R'<e)*g,[1+(e<'Y'or g)*(1+2*(y>1))*(u!=1),`w`.rfind('R')/5+1][(r>1)*o],[2-(y>r==1or'B'in w),4][(e<'C')*o],3*o*(y<1)or[6-2*g,4][x>y==1]][len(w)-3]
```
**[Try it online!](https://tio.run/##lVvbTuNIEH2Gr8jOS2wws@vgzQNDRlqvNB9Q2lapFEUaNDizSGyCTBDw9ayZCxN3n6rqvCAkH1eX@1J16lTn7nn373Yze3m57taTdfFYbcuLbvG4PKtXH/rqoXqunhb/Xd0Vj@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gJf@MY1@09RZIP300vjmtgG3qhBmFC0ZXU@Bt1RYmGRNN@q9RGqNHmWM6I@gJiDNqIS1Qn9eEGYQOB6F1pU9AwFPPopgJF05fyN2qonU5xLw83WbwPTFTTIZpyrhZ3WYwYAEcIcdtg4MoYD4YHDK8jsJwa5rmDN4pQMJxrrEj9sk2OhyEJqMnoqCDXQsKvLDoXsRHGgeKI4lqHOU7BUy2Kp3cr0fpf26A2YyU4t1jVtDKBbU57ui3tkKE@//JoSkvjo@Oru7vu35XrIuT119Ql4vF20@oj7unL93dbgDd9Teb3eTdp6ub2@56sr7p73eT9ba/eFdNXl86Puqvbu67427w4hf6r9vbb0/vJ3evY1y/e/kf "Python 2 – Try It Online")** (Tries to assert all the tests and prints a message upon completion or error.)
There may be some nice way to use bit-twiddling and get a shorter solution.
Definitely harder to understand than the manual!
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~264~~ ~~237~~ 233 bytes
```
s,i,r,u,y,b,w,z,x,t,q,p;f(S,o)char*S;{for(;s=S[i++];b+=t=s==66,r+=s==82&&(p=i),u+=s==85&&(q=i),y+=x=s==89,w+=z=s==87);S=i==4?r?z?3:u>1?q:3:2:i==5?r*o>1?p:x*!r||u==1?1:y<2?2:4:i==6?t*o?4:r==1&y>1||b?1:2:i==7?!y*o?3:y==1&w>1||r?4:6:0;}
```
[Try it online!](https://tio.run/##fZrbbiPHEYbv9RTjBbyQVpPA0tJ0QmVMoC/yALUuFApJYEgU5RBYi1oeImm9@@ybrqEETY/70x05/1QfquvwV/Us/vLbYvHt27ZdtZt23z62V@19@7l9aHftp/bu4ub4Q7s@Wfz3cvPuw8UfN@vN8cW2@/Cv1enpfy6uTrtdt@266bTdnMaPv52/fXt8161O2v3h/4/5/6f4/3jaPfRP/t7en3af@58/nVx86FZdN5lv5p/n72f7n8/mn2bvZ@ez/PDH@ebdOj@4mz28@27z5cu@687mZ7PHf5zPz2eTeGM6371bzyezTUbePv589uXLVX6hF/5p/t1jxt7PHgO7D2yT35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without the globals and non-portable return trick, 264 bytes:
```
f(S,o)char*S;{int s,i,r,u,y,b,w,z,x,t,q,p=q=t=x=z=w=b=y=u=r=i=0;for(;s=S[i++];b+=t=s==66,r+=s==82&&(p=i),u+=s==85&&(q=i),y+=x=s==89,w+=z=s==87);return i==4?r?z?3:u>1?q:3:2:i==5?r*o>1?p:x*!r||u==1?1:y<2?2:4:i==6?t*o?4:r==1&y>1||b?1:2:i==7?!y*o?3:y==1&w>1||r?4:6:0;}
```
Variable reference (unless I made a mistake):
* r: # of red wires
* u: # of blue wires
* y: # of yellow wires
* b: # of black wires
* w: # of white wires
* z: last wire is white (0 or 1)
* x: last wire is yellow (0 or 1)
* t: last wire is black (0 or 1)
* q: index of last blue wire (1-indexed)
* p: index of last red wire (1-indexed)
[Answer]
# JavaScript (ES6), ~~237~~ 222 bytes
```
(a,o,[b,u,r,w,y]=[..."BURWY"].map(c=>a.filter(x=>x==c).length),q="lastIndexOf")=>[!r?2:a[2]=="W"|u<2?3:a[q]("U")+1,r>1&o?a[q]("R")+1:a[3]>"X"&!r|u==1?1:y>1?4:2,a[4]<"C"&o?4:r==1&y>1|b?1:2,!y&o?3:y==1&w>1|r?4:6][a.length-3]
```
## Test Snippet
```
f=
(a,o,[b,u,r,w,y]=[..."BURWY"].map(c=>a.filter(x=>x==c).length),q="lastIndexOf")=>[!r?2:a[2]=="W"|u<2?3:a[q]("U")+1,r>1&o?a[q]("R")+1:a[3]>"X"&!r|u==1?1:y>1?4:2,a[4]<"C"&o?4:r==1&y>1|b?1:2,!y&o?3:y==1&w>1|r?4:6][a.length-3]
```
```
<div oninput="O.value=I.value.length>2?f([...I.value],C.checked):''">Wires: <input id="I"> Odd serial? <input type="checkbox" id="C"></div>
Result: <input id="O" disabled size="2">
```
## Tests
Tests from challenge are emulated [here](https://codepen.io/justinm53/pen/bREzpX).
[Answer]
# [Haskell](https://www.haskell.org/), ~~315 301 295 284~~ 277 bytes
Thanks to nore for saving 7 bytes.
```
c o s|l<4=z|l<5=x|l<6=q|l<7=p where b:u:r:w:y:_="BURWY";t=last s;l=length s;m=n r;k=n y;f c=[i|(x,i)<-zip s[1..],x==c];n=length.f;z|m<1=2|n u>1,t/=u=2|1>0=3;x|o,m>1=last(f r)|t==y,m<1=1|n u==1=1|k>1=4|1>0=2;q|o,t==b=4|m==1,k>1=1|n b<1=2|1>0=1;p|o,k<1=3|k==1,n w>1=4|m<1=6|1>0=4
```
[Try it online!](https://tio.run/##lVpdT1xHDH3vr7iKKiWRtmmXvd1KbG4e5qE/wKplWQhVgEiDWAjhQyGI/07vQoEd@9hz@7IimXM9nrHHH2fmy8HV6fF6/fBw1H3tru7XH/vhbvz9fbgdf5fDt/H3j@Gi@/7l@PK4O9y92b3c/b77Y/fv4U1hEn2zuh7WB1fX3dVqPayPz/@5/jL@eTacd5er0/H3x@pzdzTsndy/u52dvP/4y93JRXe1N//wYX92OwxH@6vz/7768Hl1d3/2cT7s3J93N5/ms@tfh5vxH/NPvw2L1e3919nZp/njVO8@d5fv76@H4cdsg59v8MOw@eN0RPSPX@ysvo1fjJjD8T/OxtHZZmwDPXycYoOZry5GzOn478X96QZy3n1/FLCRunyE9A933dDtHXV/Hqyvjru9t@XtrHv@2e@6YdiZHXV/Xd4cd9WgjoNPY9WH9PTz@OHCfiibH3758HmMqxlroVxNiAb5WSiS@qLOkzbVhxpIpZcp@XUdflCDQd7aOjdIRuyzsmS2Z/tDeZlS/CoFGKQao1poNSb1nvsxxmP6rEw9ptXy6019HRO/44q2phrUwB/rwchXGa/lFUB4QQYQuDxvoR4VnEMEbS1@bifhly1/ctYEoC8AP4caLSoRZMyDAfQKWECAJntF1bkahh5GgC2XdMsQZO0K4ZxlHiMoiBkFGcQjZOucz2HA2toMB2DgWT5ySbBW9lZHerpghUOg1ifAi9BsM8iGS4eQLRdMEJLNojbxuB3VKhJGAH49RjtwjsjwVLsG@Q2l@rwX58ME7Tq3IqgKGfU5oS0VpwC8cxG0GRahOHVQbVTBC60TRYjQIOxT8zhvq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gI4yFWE/oIc60Yy57vm4DVplyy9XEL624F@5hAs1XFssG1BTtG1q2SxGewmlW46DAGCYogu49PGaLXGL@4IqCoBi5GIOZvdcTR87BWYUOgrYzuOQkEZ27KJc@gTMW25UIDB48keNr2Og5jPxerqN3xxGHxLx3CxxIFJanojR@KuVisiZOlJTZtNgiED0n8kUDklWzD1PNgrdcldQ3SQ8q1RPx@8CSlmJupRYPv5ewpDCL4AgeT@J4kwXLWmBDk8JKzo8F9QojFDH@CbQdoDa/m@/gBT1oyESzuEhdTmLIbKqSHRzIiJnqVW8LnVgF2ogrkGf9IBfLVTShWUUO7hGLxDV4fP4yyNzqLxiWAZJuAboQFP2Rmu1Uw2CBoU1lqpl8B9A43FybTtZWoDMruOkrdUFfKospNAmURVltitWlcgu0vNC5KfJkG1AzOAngrDspGgTxFbDHU80myMEVPSvsYSslDMgGVMCW6oqDACZTRo6JFA6rJsgQ29bYnEcjvx@cWa4G9QGEhiL1AYWm1n0OzkgbnfHgbJTCB1S7rb65KM9JqlG6yCzFqnnEFD6VK8voR8Xw@MylkpTFvh7D8P7ARwaYgcAUNsmbJMcS2nVEjNl@TR7IlrL/8U1eQGtpiU28kwDdLhnWtb6IurBESqCT5EUGj/KjwjUp8dii@he@zR8ngssbfQxb4/rVv3Ka2sQSZ/wTLWbel8GFb/CBZApYAnEnHnb5kqGX8UpoyXta9ma6T9LIBleTdusavVxOse@S0jO@aS8aq4Hvp1wOx/9PZwcn5cHF5cn7d/dwdrNfdu2HYfP2@u3v4Fw "Haskell – Try It Online")
A totally uncreative solution in Haskell. 
Ungolfed 
```
c o s
    | l<4=z -- different function for each length; no funny business
    | l<5=x
    | l<6=q
    | l<7=p 
    where 
        b:u:r:w:y:_="BURWY" -- saving space on the quotes
        t=last s -- last is often used
        l=length s
        m=n r
        k=n y -- caching the number of reds and yellows
        f c=[i|(x,i)<-zip s[1..],x==c] -- find 1-indexed indices of the character c in the string s
        n=length.f
        z
            | m<1=2
            | n u>1,t/=u=2
            | 1>0=3
        x
            | o, m>1=last(f r)
            | t==y,m<1=1
            | n u==1=1
            | k>1=4
            | 1>0=2
        q
            | o, t==b=4
            | m==1,k>1=1
            | n b<1=2
            | 1>0=1
        p
            | o, k<1=3
            | k==1,n w>1=4
            | m<1=6
            | 1>0=4
```
[Answer]
# [Python 2](https://docs.python.org/2/), 193 bytes
```
def f(s,o):b,u,w,r,y=map(s.count,'BUWRY');l=s[-1];return+[2+(r>0<s!='UUR'),[r<1<l>'X'or u==1or y/2*2+2,1+s.rfind('R')][o*r>1],[r==1<y or-~0**b,4][l<'C'*o],[4+2*(1>r+(y==1<w)),3][y<o]][len(s)-3]
```
[Try it online!](https://tio.run/##pVZLj6JAED7Lr6hxMwG0dQUdDzNisu7jtCezrmsIMSiNskHaNE1cL/vXZ6sbfDA@J0uMYNfrq6@KKtdbsWSJ/foa0BBCIyXMfJ6RjGwIJ1tn5a@NtDlnWSKIPhiNhxPdfImd1G1Y3gunIuNJ3bXrBu@3eumDo49GQ90kLu9Zvbiv/9IZh8xxLLxtP9o1u24Tq542eRglgaGjqueyGu9bHpqgWm8LjDf@tmq1Gel4btzTP@s1hsJO3a4ZVp/Xja1U25gmaXvutsc81KKJkZqNtqcy2EScTgWbzjNhyOeUQEp55MdTFgTmswZ4VavVoYIOYkkBodA/wEL1Q5qAYIDmBFhCG0pKgyb8WEYp4MeHJFvNKAdL6nWbyqOK9AyfII5SIX210Rtn2WIJXZizGPOfL33uzwXlKYScrWAwGo4nyviAT3oYMBZTP4EQbTZLiqC4Qhb76DmIFpHYYc3tJCY0RYA8o7BC0/y3pnz3@/0SJS6STkAfyC/1NNY9okwLbto7htQdU52q3MABybN6NpVI4lEyFKlj2RJ50Cg8NnSgnbsuROo4bynVAlKjddCQV95YYO8PaYyGRxEdCfyszT5w2bYUdIRB@2CV7T/Ad8nwLM7yLjjnXNebv1m0o6HJVXPk/upgHUVM6Q1w2h5ZianOdaYQNPhJcNwx53LgNHhvCsOTFE4In@gq9v3ls26UAA2tdxtOztXuSu0vVMK@VIGnUgXKDAz0q@wXrjtX0Bd8WadMXsvrGh@De1@gC0RYl4joXm7FSRHzHjbaN2p5no3xFTbu4Lf1v@3R2bFyLOd@lFL46eOE@Mo540Z1zFmy2O0DtsNSNTUtWq0ZFxDhvBc40PGFl8tpQRPKfUGnfhxPo2SdidQo5q5aEnLMuvlwHh1NaCJfvmK2yrVwqFOUgNsm0CHwRKDrHbCq7bFT2aNorjkLsrkw8mgE011TXzh7h2aZDenlUF8V7ZuPnOQbwysry2sb0TgAQ27BYsKU1q@mqTqB7B1tD5G8iXGBpYrw@YKKinNjx2sVPMliGSU0yuPujV4Opo4dqFWwk3L/8OBA7gBDVtY4IMUpTFIok0IVNbVctfoF/zWgmKYCp/CjTEgmUIVHyMO9/gM "Python 2 – Try It Online")
Thanks to nore for [pointing out](https://codegolf.stackexchange.com/questions/125665/which-wire-to-cut#comment310352_125665) that the second three-wire condition doesn't matter. 
```
3 wires: 2+(r>0<s!='UUR')
4 wires: [r<1<l>'X'or u==1or y/2*2+2,1+s.rfind('R')][o*r>1]
5 wires: [r==1<y or-~0**b,4][l<'C'*o]
6 wires: [4+2*(1>r+(y==1<w)),3][y<o]
```
Many techniques are mixed together to do the condition logic:
* [Selecting from two list elements](https://codegolf.stackexchange.com/a/62/20260)
* [Arithmetic selection](https://codegolf.stackexchange.com/a/40795/20260)
* Boolean multiplication for logical-and
* Chaining inequalities for logical-and
* Using `or` to move past a false condition
[Answer]
# [Retina](https://github.com/m-ender/retina), 297 bytes
```
^[^R]{3}\d
2
^..W\d
3
^BB.\d
2
^...\d
3
^(?=(.*R){2,})(?=.{4}\d)(.)+(?<2>R).*1
$#2
^[^R]{3}Y\d
1
^(?=.{4}\d)[^U]*U[^U]*\d
1
^(?=.{4}\d)(.*Y){2,}.*\d
4
^.{4}\d
2
^.{4}B1
4
^(?=.{5}\d)(?=[^R]*R[^R]*\d)(.*Y){2,}.*\d
1
^[^B]{5}\d
2
^.{5}\d
1
^[^Y]+1
3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thqXiD5pgN29Y8iLT6I9nr5UnAc0hUhz65jAHJ7vA4dcxKf0ACArRnVTPRZTe5LAz6hF0kHe95Bi7t5o6Rn1qNrYBcChfMyz5ki2VbDxxUOmgLj71KbFzXHKYrG3UYCIMtb3AwUUe4yPg5jHPFoONqLomHgmHomIrQR92QSnkxhO1zOXrYufVJC0ge/0pXr1uHlIbHcC9McwMo7b2@IXRx/nQ6g/bKhS@JZTpql87X@inukEBd0vBMPAJoViANvcrkdMf6XgWI3e8cedGsvXtWxa0oRf/i0X42vsSGN9aOpW@bEMQ1n7guPeIDbr1NbqwqlMsqg3hYf/dWK5/HPk@b@eX9oEOnv6mTBYl5LqRlx54HR8DL9rLBA4R70XByHqwIqJwTSrxj1xnubUuFeWGWJ1IX4BStO372OTPrNRwtbHTDdOy9mbndfZu5PqQd79vgkXu6V/1ydS9n23u@iXP3WiZQwjiKGLy9jIKkf181lJH@gW/W3UIenZ9t818BPfbpVdu/@bc8vPp9mung3leukFu1eCm4sO73MwSf6Ix8GXeW3OYtYdzv26FQ3b0J/IrYd0RwIQGvIX4egi7gkee@/Qs "Retina – Try It Online")
A horrid mess! Takes input with the wires listed with no delimiter followed by a 1 for odd and a zero for even. I verified that it matches all the test cases given. Currently each stage (pair of lines) pretty much just encodes one rule. The main save is in the third stage where the cases where the last blue wire is the third wire can be saved by the "else" condition.
[Answer]
# [Python 2](https://docs.python.org/2/), ~~486 474 464~~, 421 bytes
Started off as the reference example (1953 bytes originally!) Is now about as unreadable as python could possibly be. 
*-10 bytes by pre-joining array to string*  
*-43 bytes thanks to [ovs](https://codegolf.stackexchange.com/users/64121/ovs) for helping get it all on one line.*
```
def f(w,o):n=len(w);l=w[-1];s=''.join(w);return[2if not'R'in w else n if l=='W'else s.rindex('U')+1if'UU'in s else n,s.rindex('R')+1if w.count('R')>1and o else 1if l=='Y'and not'R'in w else 1if w.count('U')==1else n if w.count('Y')>1else 2,4if l=='B'and o else 1if w.count('R')==1and w.count('Y')>1else 2if not'B'in w else 1,3if not'Y'in w and o else 4if w.count('Y')==1and w.count('W')>1else n if not'R'in w else 4][n-3]
```
[Try it online!](https://tio.run/##lVvBbhtHDD0nX7ENEEhuFQOyFzokUA8bJNcCRAcEYRiFYcuxC1UyJLlOv96VbEXZnXl8XF0Me/cthzPDIR/J8cN/m7vl4uz5@WZ2W90On0bLk4@L6Xy2GD6dfJpPny4@jC8/raeDwenfy/uXh6vZ5nG1uDi7v60Wy81ABveL6qmazdezalFtH86n04EOXv5en67uFzez78NBGpz8Nr6/HaS0g6/38NFPgLwCqqfT6@XjYvPy4Pfx1eKmWr6Cx3vRNtg9zEfufLodbDod/9To8MJ2Ml@en43qvbxmkA3S1mArZvcWCdhPv2krMTrfP7XXpy3JdaZHLlkPkl9UzudXX14sPpxfPm9W/318@@bp7n6@HW7725vNbL356/pqPRtVm6vVt9mmmlb3i4fHzfBk@3Y1Wz/Od49uh78ekLsX2yH2736Z7j/cSXvzsN2PTfVOV8vFt2r5uNkKqm6Xq@r9@rT6vP39/XpUre@Wj/Ob6u7q31l1/fLsXfW@GrY0eRX9Q6OTt7Pv17OHTfXlj69fVqvlajvSfpzPy38e5rPN7KbafV3tvl6fvnseDi@2Czuqfvy4HFVfr7bLcDKqzk7edt/a7u2fq8f8pbz@aH163nqrux@p/DR1R/VeGlApvYr8MSr4NB0GRZ9K/ul566V5o8pBpwTmKljj9ttULHH7rVDJxSruX@phWAUqK9s77Y4K5KqzO8r2VQ@LqOVL666D9xLNxegi2WHUxvvWnGGb1r7iKf1EiDOvDOGdlNSCtbQc5xApFqGAaG7DGGEMYVQTgXs1Lg9@hjjPEcYWTbpnbo@ocwdS2Ok4Rxh1YI71jCFEPMfR0M1JrbOY@4Fx6deyRRmXvg0vW@rucEMdJNfEcWmFrzTmw7M9dscxqoq2rJJBlA5kOJRhiLf6FoYXo3YgXVMRL5bgCDjOEepNR7pbKOX5kZaevRDA3IRsYO1DgBDt@ncw3yywoPkqtrb2OPyst/XMpdR52Eyeh8wg5kEcIl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BZo9NL4OipIzhFLb8aVg4T7c8K8N4pliygVNMX3ENyj71OUS0Qg5X57yJhYqmT5DXXcOWwKeHNFq9R5ArOvGgTCuZZiwC/osw8BXhmjW/DpGPABllLnVd9m7DlIDAzxeFJvHzBtQpUWKQKsxYOBiea4ggsHTITMq/J4YJZzwGDe5xqC@4X4Ko3J1oCaWGosoX8QkDfyj1PSus93q3lJr5dpiBM9tBCQAvC00IAI3IFm58nTyBWqFkoyEXE8UOoK6F0KVArmwou4mVhFQgrR8jlS5y8A@KC9QiNNeROqAPTOKm65s0GFiFdsIWCLd5ngWk13g8UIakSEntvBVWy5FFOhZWQSAsNWaR6kbdhcs2vONflP0NEGQBK3bxEFjfeon/ISGEOqSCgF9gJvD0q4WnGijibbJBDhmB8UxhjKQ3CFCHCohsd6MJmAwMIA4v/jxW13wDsITh2bAbciZfyGiyNO1UTBE7HgN3KmwGn5p07o2EUrVvqaZvmdRaMXRhuYt5mNHzEgiW@TdzEHNZA1O@hMuEUGKvHYlOsceZnGyZYY/JooLzCr2wjCqkUnI4BC2lDYHCiyZvBS3zRhXNUhAD@oijcZoEMY4WWhYub5CiiT3ysMmdo0RVeDHaucE1ge7yhtRvcSy@OyP8 "Python 2 – Try It Online")
[Answer]
# R, 407 Bytes
Golfed Code 
```
pryr::f(a,n,{r=a=='R';u=a=='U';l=paste(length(a));s=sum;R=s(r);Y=s(a=='Y');v=4;switch(l,'3'={v=3;if(R<1){v=2}else if(s(u)>1){v=tail(which(u),1)}else{}},'4'={if(R>1&&n){v=tail(which(r),1)}else if(a[4]=='Y'&&R<1||s(u)==1){v=1}else if(Y>1){}else{v=2}},'5'={v=1;if(a[5]=='B'&&n){v=4}else if(R==1&&Y>1){}else if((a=='B')<1){v=2}else{}},'6'={if(Y<1*1){v=3}else if(Y==1&&s(a=='W')<2){}else if(R<1){v=6}else{}});v})
```
Ungolfed 
```
function(a,n){
   r=a=='R'
   u=a=='U'
   l=paste(length(a))
   s=sum
   R=s(r)
   Y=s(a=='Y')
   v=4
   switch(l,'3'={
   v=3
   if(R<1){
     v=2
   }else if(s(u)>1){
     v=tail(which(u),1)
   }else{}
   },'4'={
   if((R>1)*n){
      v=tail(which(r),1)
   }else if((a[4]=='Y')*(R<1)||s(u)==1){
      v=1
   }else if(Y>1){
   }else{
     v=2
   }
   },'5'={
     v=1
   if((a[5]=='B')*n){
     v=4
   }else if(R==1&&Y>1){
   }else if((a=='B')<1){
     v=2
   }else{}
   },{
   if((Y<1)*n){
     v=3
   }else if((Y==1)*(s(a=='W')<2)){
   }else if(R<1){
     v=6
   }else{}
 })
 v}
```
### Explanation
This assumes that the input will be an ordered list. 
Saved bytes by storing the logical array of where the Red and Blue wires were. 
The logical array can be summed to count the number of wires of that color and be used to find the last red and last blue wire index. 
Storing the function sum as s saved bytes due to the number of times it was called. 
Converting the number of wires to a character for the switch statement was done using paste, which is less bytes than as.character()
Initializing the variable v, the number of the wire to cut,to 4 before switch statement allows for the me not to have to add that statement each time the wire number is 4. 
For length of 4 the second and third conditions can be combined with an or statement to reduce the numbers of ifelse since they evaluate to the same wire to cut. 
[Answer]
# Excel VBA, ~~521~~ ~~446~~ 419 Bytes
Full subroutine that takes input of expected type `Array` and `Boolean (or Truthy/Falsy)` and outputs which wire you should cut to range `[A4]`.
```
Sub c(x,s)
i=UBound(x)
[A1].Resize(1,i+1)=x
[A2].Resize(1,5)=Split("B U R W Y")
[A3]="=COUNTIF(1:1,A2)"
[A3].AutoFill[A3:E3]
j=x(i)
B=[A3]
u=[B3]
R=[C3]
W=[D3]
y=[E3]
[A4]=Choose(i-1,IIf(R,IIf(j="U",i+1,IIf(U>1,InStrRev(Join(x,""),"U"),i)),2),IIf(s*(R>1),InStrRev(Join(x,""),"R"),IIf((j="Y")*(R=0)Or u=1,1,IIf(y>1,i,2))),IIf(s*(j=8),4,IIf((r=1)*(y>1),1,IIf(b,1,2))),IIf((y=0)*s,3,IIf((y=1)*(w>1),4,IIf(r,4,i))))
End Sub
```
### Example I/O
*Note:* In order to pass an array in VBA it is necessary to use either an Array or split statement
```
c Array("B","R","R"),FALSE 
 3 
```
[Answer]
## JavaScript (ES6), ~~252~~ 244 bytes
Test cases can be viewed in [this codepen](https://codepen.io/ajxs/pen/ZyWJRz).
```
d=(a,o,[b,u,r,y,w]=[..."BURYW"].map(i=>a.filter(t=>t==i).length),q="lastIndexOf")=>[!r?2:a[2]=='W'?3:u>1?a[q]('U')+1:3,r>1&&o?a[q]('R')+1:a[3]=='Y'&&!r?1:u==1?1:y>1?4:2,a[4]=='B'&&o?4:r==1&&y>1?1:!b?2:1,!y&&o?3:y==1&&w>1?4:!r?6:4][a.length-3];
```
]