text:
Vending Machine
The Task
Build a function that takes a string of coins ending with an item index, and generates change as a string of coins using the least amount of coins possible.
The following are the items that can be bought (0-indexed):
[0.45, 0.60, 0.75, 0.95, 1.10, 1.25, 1.40, 1.50, 1.75, 2.00]
The following are the coins that can be used, with their abbreviations:
n = 0.05
d = 0.10
q = 0.25
D = 1.00

If an invalid item is selected, or the coins supplied are not enough to purchase the item, all $ is returned in the least number of coins possible.
If exact change is given, an empty string should be returned
Test Cases
Dq4 = dn
qqqq4 = D
qqddddd10 = D
qqn0 = d
Dddd5 = n
qq0 = n
DD3 = Dn
Dd4 =
DDnn9 = d

Assume that input will only contain valid coin characters and will always terminate in an integer.
This is my first posted question, so be please be gentle when telling me how I screwed up asking it. :)

Related

Is that a bad thing? I tried to come up with something new and pulled this from some c++ homework I did a few years ago.

Welcome to PPCG, in the future you should submit your questions to our sandbox for feedback before posting your question.  That way you don't have to worry about people "being gentle" on your first post

You need to clarify the inputs here. Are there three inputs (map of coin values, list of item prices, string of coins)?

Understood on both counts, I will post to sandbox and attempt to link related questions for future posts.

yes, those are always the item prices, and the input is a single string which contains both the coins and item

Looks good to me, thank you for helping with clarification

for exact change given, an empty string should be returned

Since you have exactly 10 options, it will help potential programs if the last digit is always an integer, and it is the only digit that is an integer, i.e., qqddddd10 wouldn't be valid input. That way there's no typechecking involved.

I'm pretty sure I said the same thing to my teacher at the time and he told me that was just part of the lesson. My solution for it was to immediately check if the string contained more than one digit and then just return the $

May we assume the integers will always be non-negative (I don't remember seeing negative keys on vending machines)?

yes, all terminating integers will be positive

Python 3 - 219 213 Bytes
Fixed whitespace...
So this is awful as of right now....
def x(s):
 v={'n':.05,'d':.1,'q':.25,'D':1}
 r=sum([v[c]for c in s[:-1]])-[.45,.6,.75,.95,1.1,1.25,1.4,1.5,1.75,2.0][int(s[-1])]
 o=''
 for x in'Dqdn':
    r=round(r, 2)
    while v[x]<=r:
     r-=v[x]
     o+=x
 return o

I'll go back to see if I can't get it golfed down at all...

Watch your whitespace. You can use tabs (although they don't show up in PPCG) and spaces alternatively also. IE, for the first level, one space. For the second level, one tab. For the third level, a tab and a space. Right now you have 5 (!) spaces for your third level.

I've never figured out how to get that to work right in tio xD

In regards to your comments about the test cases, If an invalid item is selected, or the coins supplied are not enough to purchase the item, all $ is returned in the least number of coins possible.

I guess I should read more carefully

@StephenS Since this is Python 3, they can't mix tabs and spaces.

@L3viathan Oh, shows my lack of Python knowledge. Thanks. They can cut down the number of spaces though, correct?

@StephenS Sure, one space per indentation is enough.

You can also define v outside the function to save one byte.

@carusocomputing The prices aren't increasing by a constant .15

@PunPun1000 you're right, I think range(.45,1.4,.15)+range(1.5,2,.25) will help, though I know little about Python.

Your code is not working for two of the test cases, TIO

Java (OpenJDK 8), 281 271 bytes
-10 bytes thanks to Jonathan Allan

p->{int d[]={9,12,15,19,22,25,28,30,35,40},v[]={20,5,2,1},s=0,t;String m="Dqdn",n="";for(char c:p.toCharArray())s+=(t=m.indexOf(c))<0?0:v[t];t=p.charAt(p.length()-1)-48;s-=p.matches(".*\\d\\d")|s<d[t]?0:d[t];for(t=0;s>0;)if(s>=v[t++]){n+=m.charAt(--t);s-=v[t];}return n;}

Lambda that takes and returns a String
Try it online!
Ungolfed:
p->{
    int d[]={9,12,15,19,22,25,28,30,35,40},
        v[]={20,5,2,1},
        s=0,
        t;

    String m="Dqdn",
           n="";

    for(char c:p.toCharArray())
        s+= (t=m.indexOf(c))<0 ? 0 : v[t];

    t=p.charAt(p.length()-1)-48;
    s-= p.matches(".*\\d\\d") | s<d[t] ? 0 : d[t];
    for(t=0;s>0;)
        if(s>=v[t++]){
            n+=m.charAt(--t);
            s-=v[t];
        }
    return n;
}

@JonathanAllan Nice catch

Python 2, 192 176 bytes
-16 bytes thanks to @JonathanAllan
s=input()
v=0
while s[0]in'qndD':v+=[1,2,20,5][ord(s[0])%11];s=s[1:]
x=int(s)
v-=x<10and x<=v and[9,12,15,19,21,25,28,30,35,40][x]
print v/20*'D'+v%20/5*'q'+v%5/2*'d'+v%5%2*'n'

Try it online!

I may be wrong, but I think your golfed program's outputs are off for a few test cases (Dq4, qqqq4, Dd4).

PHP, 258 Bytes
$i=array(45,60,75,95,110,125,140,150,175,200);$c=array(D=>100,q=>25,d=>10,n=>5);$a=str_split($argv[1]);$p=$i[array_pop($a)];foreach($a as $x){$t+=$c[$x];$p=$c[$x]?$p:0;}$p=$t<$p?0:$p;while($t>$p){foreach($c as $n=>$x){if($t-$p>=$x){$t-=$x;echo $n;break;}}}

Ungolfed:
$i=array(45,60,75,95,110,125,140,150,175,200);
$c=array(D=>100,q=>25,d=>10,n=>5);
$a=str_split($argv[1]);
$p=$i[array_pop($a)];
foreach($a as $x){
  $t+=$c[$x];
  $p=$c[$x]?$p:0;
}
$p=$t<$p?0:$p;
while($t>$p){
  foreach($c as $n=>$x){
    if($t-$p>=$x){
      $t-=$x;
      echo $n;
      break;
    }
  }
}

your coin array declaration is missing quotes and $t needs to be defined before you can add to it
$c=array('D'=>100,'q'=>25,'d'=>10,'n'=>5);
$t=0;
Once I added those I was able to run and get some good results, but qqddddd10 failed

It worked for me, but maybe there's differences in PHP versions (I'm using  5.3.29). I seem to be able to get away with not initializing variables, and it just acts like it was 0 to begin with. Maybe there's error notifications not showing because of my PHP configuration?

JavaScript (ES6), 230 219 bytes
-10 bytes thanks to @JonathanAllan's idea of dividing all values by 5.
-1 byte by moving b="Dqdn" into the empty s.pop() function call.
s=>(a=[20,5,2,1],s=s.match(/\D|\d+/g),i=[9,12,15,19,22,25,28,30,35,40][s.pop(b="Dqdn")]||0,p=s.map(c=>a[b.search(c)]).reduce((y,z)=>y+z,0),(c=p-i)<0&&(c=p),a.map(v=>(x=c/v|0,c-=x*v,x)).map((v,j)=>b[j].repeat(v)).join``)

Ungolfed
input => {
    values = [20,5,2,1];
    coins = "Dqdn";
    input = input.match(/\D|\d+/g);
    item = [9,12,15,19,22,25,28,30,35,40][input.pop()] || 0;
    payment = input.map(c => values[coins.search(c)]).reduce((y,z) => y+z, 0);
    change = payment - item;
    if (change < 0) change = payment;
    return values.map(val => {
        count = change/val | 0;
        change -= count * val;
        return count;
    }).map((count,j) => coins[j].repeat(count))
    .join``
}

Test Snippet

f=
s=>(a=[20,5,2,1],s=s.match(/\D|\d+/g),i=[9,12,15,19,22,25,28,30,35,40][s.pop(b="Dqdn")]||0,p=s.map(c=>a[b.search(c)]).reduce((y,z)=>y+z,0),(c=p-i)<0&&(c=p),a.map(v=>(x=c/v|0,c-=x*v,x)).map((v,j)=>b[j].repeat(v)).join``)
Input
<input oninput="O.value=/\D+\d+/.test(I.value)?f(I.value)||`<empty>`:``" id="I">
Result
<input id="O" disabled>

@JonathanAllan Good thinking, that did indeed save 10 bytes. Thanks!

C++, 375 371 370 bytes
-5 bytes thanks to Zacharý
#include<map>
#include<vector>
#include<string>
std::map<int,int>c={{'n',1},{'d',2},{'q',5},{68,20}};void v(std::string&e){int m=0,i=0,h=0;for(;i<e.size();++i)h+=e[i]>47&&e[i]<58;m=i=0;for(;i<e.size()-1;++i)m+=c[e[i]];if(h==1){i=std::vector<int>{9,12,15,19,22,25,28,30,35,40}[e[e.size()-1]-48];m-=(m>=i)*i;}e="";for(auto&g:{68,113,100,110})while(m>=c[g]){m-=c[g];e+=g;}}

h+=(e[i]>47&&e[i]<58) can be h+=e[i]>47&&e[i]<58, since && has higher priority than assignment/modified assignment. m=(i=0) can be m=i=0 since assignment's associativity is right-to-left, and I also think that can be moved into the for-loop that follows it. And also, can the 'D' become 68?

I'm assuming replacing 'D' with 68 didn't work?

@Zacharý Replacing 'D' alone with 68 does not work, because of the auto keyword usage, if you have 2 different types ( even implicitly cast-able, like int and short ), the compiler can't guess what type you want and will return an error. It's the same rules as c++ template type argument declaration, where all types must match exactly. I switched all list from char to int

264 bytes

Jelly,  68  64 bytes
Vị“€ÐŒæı÷œ#(µ‘
ḟ®µL⁼1ȧÇ
“Þ¦£‘ɓ“Dqdn”©iÐ€ị⁹;1,0¤S¹_<?⁸Ç¤;%\:⁹®żŒṙ

A monadic link taking and returning lists of characters.
Try it online! or see the test suite.
How?
Vị“€ÐŒæı÷œ#(µ‘ - Link 1, item price / 5: list of digit characters, d  e.g."4"   or "10"
V              - evaluate d as Jelly code                                  4        10
  “€ÐŒæı÷œ#(µ‘ - code page indexes = [12,15,19,22,25,28,30,40,9]
 ị             - index into (1-indexed and modular)                       22        12

ḟ®µL⁼1ȧÇ - Link 2, item price / 5: list of characters, s              e.g."Dq4" or "Dq10"
 ®       - recall register value = "Dqdn" (see Main)
ḟ        - filter discard from s                                          "4"      "10"
  µ      - monadic chain separation, call that d
   L⁼1   - length equals 1?                                                1         0
       Ç - call last link as a monad                                      22        12
      ȧ  - logical and                                                    22         0

“Þ¦£‘ɓ“Dqdn”©iÐ€ị⁹;1,0¤S¹_<?⁸Ç¤;%\:⁹®żŒṙ - Main link: list of chars, s    e.g."Dqqqq4"
“Þ¦£‘                                    - code page indexes = [20,5,2]
     ɓ                                   - dyadic chain separation, left=s right=that
      “Dqdn”                             - literal = "Dqdn"
            ©                            - copy to register and yield
              Ð€                         - map across c in s:
             i                           -   1st index (0 if not found)  [1,2,2,2,2,0]
                      ¤                  - nilad followed by link(s) as a nilad:
                 ⁹                       -   chain's right argument = [20,5,2]
                   1,0                   -   1 pair 0 = [1,0]
                  ;                      -   concatenate = [20,5,2,1,0]
                ị                        - index into (1-indexed)       [20,5,5,5,5,0]
                       S                 - sum                                    40
                              ¤          - nilad followed by link(s) as a nilad:
                            ⁸            -   chain's left argument = s
                             Ç           -   call last link as a monad(s)         22
                           ?             - if:
                          <              -          less than (coins not enough?)  0
                        ¹                - ...then: identity (do nothing, would be 40)
                         _               - ...else: subtract                      18
                               ;         - concatenate with right          [18,20,5,2]
                                 \       - cumulative reduce by
                                %        -   modulo                        [18,18,3,1]
                                   ⁹     -   chain's right argument = [20,5,2]
                                  :      - integer division                [ 0, 3,1,1]
                                    ®    - recall register value = "Dqdn"
                                     ż   - zip       [['D',0],['q',3],['d',1],['n',1]]
                                      Œṙ - run-length decode                   "qqqdn"

this is the largest Jelly program I've ever seen, by a significant margin

@Mayube Prospective meme re-tag: "longest Jelly". Google search (this submission actually does have less in the way of bytes used for compressed data than many I believe).


text:
Pad a file with zeros
Your task today will be to take an existing file and append zeros to it until it reaches a certain size.
You must write a program or function which takes the name of a file in the current directory f and a number of bytes b. While maintaining the original content of f, you must write zeroes (null bytes, not ascii 0s) to the end so that its new size is b bytes.
You may assume that f only has alphanumeric ascii in its name, that you have full permissions over it, that it initially is not larger than b, but may be as large as b, and that there is infinite free disk space.
You may not assume f is nonempty, or that it does not already contain null bytes.
Other existing files should not be modified and new files should not exist after execution ends.
Test Cases

Contents of f | b  | Resulting contents of f
12345         | 10 | 1234500000
0             | 3  | 000
[empty]       | 2  | 00
[empty]       | 0  | [empty]
123           | 3  | 123

@totallyhuman it initially is not larget than b

Can we take the contents of the file as input and output the modified contents?

May we use libraries?

@Phoenix The problem is that Dennis put the library in a far away folder (not my choice). Can I count as if it was available in the search path?

Can we assume the file will not already contain null bytes?

Bash + coreutils, 13
truncate -s$@

Input from the command-line - the first parameter is the file size and the second is the filename.
From man truncate:

If a FILE is shorter, it is extended and the extended part (hole) reads as zero bytes.

Try it online.

Can truncate extend too?

A man who knows his mans in a manly man indeed.

I wonder if it works on a FAT partition, where the truncate syscall fails.

My implementation of the same idea would have been dd bs=1 of=$1 seek=$2<&- (which prints an error message that can be ignored). Yours is far shorter. Nice.

@hvd yep I figured dd could probably do this

Groovy, 54 47 43 41 bytes
{a,b->(c=new File(a))<<'\0'*(b-c.size())}

-6 thanks to manatwork's idea of removing the loop; that was my original idea, don't know why I thought it wouldn't work and opted for a loop... It definitely works, just tested it.
Ungolfed:
{
    a,b->                    // Two inputs: a is the File name, b is the desired size.
    File c = new File(a)     // Make and store the file.
    c << '\0'*(b-c.size())   // Append the difference between b and c.size() in nullbytes.
}
                             // Usually a close would be required, but, in Groovy,
                             // because private data isn't so protected, if a File
                             // Object goes out of scope, the attached Stream is
                             // automatically flushed to disk.

Wouldn't be shorter loopless? {a,b->c=new File(a);c<<('\0'*(b-c.size()))}

@manatwork yeah! And it can actually be even better than that.

@manatwork nevermind, same bytecount for (c=new File(a)) due to required parenthesis.

No idea why I put parenthesis around the entire value to append. Not needed.

@manatwork Groovy is pretty temperamental about the parenthesis, can't blame you haha.

APL (Dyalog), 33 17 bytes
⎕⎕NRESIZE⍞⎕NTIE¯1

Try it online!

What's ∇Extend?

@Phoenix Just the name of the program so it can be called. Here is a version without naming the program.

Python 2, 59 57 54 bytes
-5 bytes thanks to chepner

def g(n,b):f=open(n,'a');f.write('\0'*b);f.truncate(b)

@totallyhuman \x00 is a null byte.

@totallyhuman no, it is more like a flag thing (to disallow interactino with closed files)

@Rod I love interactino! Best child-friendly interactive game ever

You can use \0 in place of \x00.

You can save another three bytes by overextending, then truncating: def g(n,b):f=open(n,'a');f.write('\0'*b);f.truncate(b).

Can you do f=open(n,'a').write('\0'*b)?

@ComradeSparklePony yeah, but it would return None

PHP, 66 bytes
for($p=fopen($f=$argv[1],a);filesize($f)<$argv[2];)fputs($p,"\0");

Takes input from command line arguments; run with -nr.

These 55 bytes might, but most probably will not, work:
fseek($p=fopen($argv[1],"w+"),$argv[2]);fputs($p,"\0");

Java (Oracle JRE), 55 bytes
f->b->new java.io.RandomAccessFile(f,"rw").setLength(b)

The spec of setLength(int) says that the appended bytes are undefined, but practically the Oracle JRE appends only the 0 byte (that's why I specified it).
The resource is automatically closed by the JVM so we don't need to do it ourself.
Test
public class Pcg125661 {
  interface F {
    B f(String f);
  }
  interface B {
    void b(int b) throws java.io.IOException;
  }
  public static void main(String[] args) throws java.io.IOException {
    F a = f->b->new java.io.RandomAccessFile(f,"rw").setLength(b);
    a.f("a").b(100);
  }
}

AHK, 48 bytes
FileGetSize,s,%1%
2-=s
Loop,%2%
FileAppend,0,%1%

1 and 2 are the first two parameters in an AHK script.
FileGetSize works in bytes by default.
It's not exciting, but it's simple: Get the size, subtract it from the desired size, and add that many zeroes.

Perl 6, 40 bytes
{$_=$^a.IO;.open(:a).put("\0"x($^b-.s))}

$^a and $^b are the parameters to the function--the file name and the length, respectively.

Python 2, 68 bytes
def g(f,b):
 with open(f,'r+')as c:c.write('\x00'*(b-len(c.read())))

Try it online! (When printing the file's content, the code replaces null bytes with ASCII 0's for visibility.)

I think this writes ASCII zeroes and not null bytes

Ah... the word zeroes was misleading...

Well, it does say in large letters in the challenge itself.

Can you use a literal \x00 in the string (not an escape sequence)?

You can't use a literal null byte, but \0 is shorter.

PowerShell, 69 bytes
param($f,$s)@(gc $f -en by)+,[byte]0*($s-(gi $f).length)|sc $f -en by
#     ^ filename
#        ^desired size
#                 ^ get content as byte stream
#           ^force it to an array even if there's 0 or 1 byte
#                          ^append a byte array of nulls..
#                                       ^..desired size - file size
#                            write to file with -encoding byte ^

$f for the file, $s for the destination size, save as .ps1 and run
.\Add-NullBytesToFile.ps1 .\test.txt 10

It's a shell, so there should be a really small loop adding 1 byte with >> output redirection and append, right? Well, no, because >> only outputs UCS2-LE multibyte encoding so there's no way to add a single byte to a file with it .. unless you're using PSv5.1 and you can change that but that makes it too long to be competitive:
$PSDefaultParameterValues['Out-File:Encoding']='utf8';while((gi $f).length-lt$c){[byte]0>>$f}

Maybe there's a .Net Framework approach? There should be, but I can't make it actually write any bytes, or error. But it's longer anyway:
param($f,$s)[io.file]::WriteAllBytes($f,[byte[]](,0)*($c-(gi $f).length), $True)

Mathematica 50 Bytes
Import/Export
Export[#,Import[#,c="Byte"]~Join~Table[0,{#2}],c]&

Usage
%["test1", 5]

C, 56 bytes
fseek(f,0,2);int i;for(;ftell(f)<b;)putc(0,f);fclose(f);

The program finds the file's size, and how many bytes to append. The file then adds fs - b extra bytes to the end.

Welcom to PPCG! This is a [tag:code-golf] challenge, so your objective is to make your program as small as possible. You should start by removing unnecesary whitespace.

In addition, your program seems to assume that the inputs are already stored in the values f and b, which isn't allowed. You must include i/o into your program, which can be from ARGV, console input, or arguments to a function.

Thank you, I thought that the variables were assumed to be set already. My bad.

q, 29 bytes
Function which takes file name in format :/foo/bar.baz and length as an integer.
{hopen[x](0|y-hcount x)#0x00}

Example:
{hopen[x](0|y-hcount x)#0x00}[`:test.txt;100]

C#, 90 bytes
using System.IO;s=>n=>File.AppendAllText(s,new string('\0',(int)new FileInfo(s).Length-n))

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Which wire to cut
This task is about compressing and processing a sequence of conditionals.

In the game Keep Talking and Nobody Explodes, a bomb defuser must disarm a bomb with the help of instructions relayed by experts consulting a convoluted Bomb Defusal Manual. 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
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)
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).
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>

...so when they say "never cut the blue wire", they really should say "never cut the fifth wire" (counts of "wires to cut" by index: 4453, 2359, 4252, 22045, 0, 5891).

@Notts90 UUR is the only combination that it matters for, right? I'll add it to the test cases.

For languages like C, can we take the number of wires in addition to the input of characters?

@ConorO'Brien Can C and similar take a string or list with a terminator instead?

@xnor A string, yes. A list, possibly. Would a string be an acceptable substitute for the unordered list?

@ConorO'Brien Yes, a string would be fine. I'll say a list can end in a reasonable terminator as well.

Complicated Wires when? :P

Don't bother posting a question about Big (Red) Buttons. The solution is (almost always) "press and hold, then release when timer is..." I'd have to grab my defusal manual to recheck things.  But so much of it boils down to the final "else" statement of "see press and hold." (It got to the point where I was able to defuse that module myself with no instruction).

I think all solutions could save a few bytes by noticing the second case where there are 3 wires is useless: if that case should trigger, there are at least one red and one white wires, so there can't be more than one blue wire, and the default case will take care of it.

JavaScript (ES6), 210 203 199 187 180 bytes
Saved 7 bytes thanks to nore.

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);
}

That currying syntax is quite a nice byte-saver.

Would it be possible to test this on the full set of 39000 inputs generated by my TIO?

@xnor I've added an exhaustive test against a port of your Python code.

Congratulations, I awarded you the bounty for a well-optimized solution, with a clever efficiently queryable representation of the wires. It was a close decision between this and Jonathan Allan's Python solution.

Python 2,  300  214 bytes
-12 bytes thanks to a comment made by nore (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! (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!

It looks like some of the length-3 results are wrong on the full set of possible inputs.

That fixes it for 7 with u<2 -> u<2or'R'<e (the four failure cases were when there were 2 blue wires and a red wire and the last was blue, when it would return 2 rather than 3).

Haskell, 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!
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

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.

C (gcc), 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!
Version 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)

You can save 5 bytes by replacing return i==4... with S=i==4.... Try it online!

@ConorO'Brien That requires the less general language of C (gcc) instead. That won't work at all in, e.g. clang.

@FryAmTheEggman Not only gcc, it works in tcc as well. Most compilers do it that way, I think that clang is just a weird compiler. But yeah, its not standard.

Python 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!
Thanks to nore for pointing out 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
Arithmetic selection
Boolean multiplication for logical-and
Chaining inequalities for logical-and
Using or to move past a false condition

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
^(?=[^Y]*Y[^Y]*\d)(.*W){2,}.*.
4
^[^R]+.
6
^.+.
4

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.

Sorry, your 3-blue-wire bomb just blew up because you cut the middle wire instead of the right-hand wire.

@Neil A 3 blue wire bomb has no red wires, so the middle wire is correct! Unless I read something wrong?

I had only just come to that conclusion myself. Sorry for the false alarm!

Python 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 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!

You can take off another 20 to 444 by bringing the cases into a dict and evaling them. TIO: https://goo.gl/pvSjoi

Why is this noncompeting?

@orlp when I started all I'd done was remove white space and rearrange if statements from the example, I didn't feel at that point there was anything special or competitive about it but hoped to be able to do more. Now I have done the extra bits I guess it could be competing.

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.

You may want to look at this tip.  It should help shave off a number of bytes. eg "if"(R<1,v=2,"if"(s(u)>1,v=tail(which(u),1),)) vs if(R<1){v=2}else if(s(u)>1){v=tail(which(u),1)}else{}

I think you can get away with | and & rather than || and && in your conditionals.  If you aren't using defaults in the switch, you can pass in an integer.  Your ungolfed looks like it does use a default, but your golfed code doesn't

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

JavaScript (ES6), 252 244 bytes
Test cases can be viewed in this codepen.
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];

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Regular expression parser
This task is a classic programming task: Implement a regular expression parser. That is, write a program or function which takes a string describing a regular expression and a candidate string, and test whether the complete candidate string matches the regular expression. You may assume that the regular expression passed is valid.
If your programming language offers regular expression matching or string parsing, you are not allowed to use that. Also you are not allowed to use libraries other than the standard library of your programming language. Also forbidden is to access an external tool to do the work (e.g. accessing a web server, or calling another executable). In addition, use of reflection or any other functionality that allows the program to access its own source code, the names of individual identifiers or similar information is explicitly forbidden to prevent gaming the scoring rules (thanks to ais523 in the comments for making me aware of the latter possibility).
This is an atomic code golf contest, it's not the character count that has to be minimized, but a modified token count (for details, see below).
Input
The regular expression is not enclosed in slashes (/), any slashes appearing in the regular expression string are part of the regular expression itself (that is, the string /.*/ denotes not the regular expression .*, but the regular expression /.*/ which will match the string /abc/, but not the string abc).
Both the regular expression string and the candidate string will consist solely of ASCII characters in the range 32 (space) to 126 (tilde).
The regular expression syntax
Your program only needs to parse the following minimal regular expression syntax:

Anything except the letters ., *, |, (, ) and \ matches literally.
A backslash (\) followed by any of the above characters literally matches the second character.
A dot (.) matches any character.
The star (*) matches zero or more consecutive strings each matching the regular expression preceding it. It cannot appear at the beginning.
The pipe (|) matches either the regular expression before it, or the regular expression following it.
Parentheses ((, )) themselves don't match anything, but are used to group expressions (e.g. ab* matches abbbbb, while (ab)* matches abababab).

Output
Your program or function must give one of two results, one indicating that the complete candidate string matches, one indicating that it doesn't. How the output is given (function return variable, global variable setting, text output, program status code, ...) is up to you (and the capabilities of your chosen programming language). Explain how the output is to be interpreted.
Scoring
Of course, this being a code golf, the minimal score wins. The score is calculated as follows:

Start with score 0.
Comments and whitespace characters that are not part of a token are ignored.

Rationale: I don't want to penalize pretty formatting. The token exception covers both spaces inside string and character constants, and special cases like the Whitespace language where each single whitespace character constitutes a token (so writing a program in Whitespace won't give you a score of 0).

For any statement/declaration/etc. which makes available a standard library component to the code (like #include in C, use in Perl or import in Java), add 5 point per imported standard library package.

Rationale: I don't want to make the scoring dependent on how verbose the import syntax of a language is. Also, there shall be a slight (but not too strong) discourage of using library components (direct code is preferred, unless the library makes a big difference; however note the restrictions on library use outlines above). The "per standard library package" part is so that you cannot reduce your point by combining several imports by one (e.g. in Turbo Pascal, you could write uses dos, crt; instead of uses dos; uses crt;. With the rule as given, both would add 10 points. (Of course, both dos and crt would be pointless for the given task.)

For any string, add one more than the number of characters in the string (that is, the empty string gets 1 point, a one character string gets 2 points, etc.). If the language has single-token literals for other complex types (like lists, dictionaries, etc.), it is one point per character in the literal. (thanks to ais523 in the comments for telling me about such complex literals).

Rationale: This is mainly to prevent tricks like eval("long program code") which is four tokens. With this rule, doing such a trick actually penalizes your code, because you're back to character counting instead of token counting.

For any number, add as many points as the minimal number of bytes needed to represent the number as either signed or unsigned two's-complement number. That is, numbers from -128 to 255 (including both values) get 1 point, otherwise numbers in the range -32768 to 65535 get 2 points, otherwise numbers in the range -8388608 to 16777215 get 3 points, and so on.

Rationale: This is to prevent similar tricks in languages supporting arbitrary large numbers, where the whole program might be encoded in a number that is then reinterpreted as a string and passed to eval or an equivalent function.

Any token not covered in the list above gives 1 point.

Rationale: This is to avoid penalizing verbose languages (e.g. Pascal with begin/end vs. C with {/}), and especially to avoid giving esoteric languages (Golfscript!) an advantage just for having one-character tokens. Also, it allows meaningful variable names without being penalized.

Note: This challenge was posted in the sandbox

I can see a few ways to exploit the scoring rules here; not sure if they'd actually save score, but they might. (For example, use a very long identifier name, then find the longest identifier in the program, shift the bytes in it, and eval it.) One thing you should probably deal with is literals for structures other than strings and integers; some languages have, e.g., a list literal or an XML literal that's only a single token.

You say that "" followed by a special character matches that character literally. Is there defined behavior for "" followed by a non-special character? Or is that just invalid syntax?

@Tutleman: You don't need to handle that case, and if you do, you can do whatever seems advantageous for your code.

Python 3, 445* points
This is a fairly straightforward approach: it uses a basic recursive descent parser, and a regex engine implemented using Brzozowski derivatives (which I just learned about, and which I think are super elegant); it takes two strings as input via STDIN – first a string representing the regex in question, then a string containing the text to match, and prints True to STDOUT if the regex matches and False if it doesn't.
class Nil:nullable,derive = False,lambda *self: Nil
class Empty(Nil):nullable = True
class And:
    def __init__(self, first, second=None):self.first,self.second = first,second
    nullable = property(lambda self: self.first.nullable and self.second.nullable)
    def derive(self, c):
        dxy = And(self.first.derive(c), self.second)
        return Or(dxy, self.second.derive(c)) if self.first.nullable else dxy
class Or(And):nullable,derive = property(lambda self: self.first.nullable or self.second.nullable),lambda self, c: Or(self.first.derive(c), self.second.derive(c))
class Star(And):nullable,derive = True,lambda self, c: And(self.first, Star(self.first)).derive(c)
class Plus(Star):nullable = False
class Char(Plus):derive = lambda self, c: Empty if self.first in 'µ'+c else Nil
expr = input()
index = len(expr)
peek = lambda: index and expr[-index] or ''
def advance():
    global index
    item = peek()
    index -= True
    return item
def regex():
    factor = Empty
    while peek() not in ')|':
        current = advance()
        base = Char(current)
        if current == '(':
            base = regex()
            advance()
        elif current == '\\':base = Char(advance())
        elif current == '.':base = Char('µ')
        while '' < peek() in '*+':
            base = (Star if peek() == '*' else Plus)(base)
            advance()
        factor = And(factor, base)
    return Or(factor, regex()) if peek() == '|' == advance() else factor
derivative = regex()
for c in input(): derivative = derivative.derive(c)
print(derivative.nullable)

Try it online!

* I'll be honest: I'm not totally sure if I've scored this correctly, because the scoring rules for this submission are at once both rather complex and also imprecise. Their goals are certainly admirable, but I think the range of possible situations they try to cover is too vast.
As an example of what I mean: "Tokens" aren't necessarily a consistently defined concept in many programming languages, and this challenge doesn't clarify. In Python, for instance, they're implementation-defined.
Similarly, and among other such things, the challenge doesn't count whitespace against a score unless it's part of a token, but CPython generates tokens for certain non-meaningful whitespace, which leads to a contradiction with the scoring rule's stated intent of "avoiding penalizing pretty formatting."
Consequently, this could actually be anywhere from 407-533 points.

is not included in the question's regex subset


text:
Find patterns in numbers based on the similarity of characters?
Task
The task is to write a script that accepts a number from 1 to 20 inclusive. It will then check if the number has a character that is found in every number that was entered before it. If the number has a character in common it will ask for another number. However if the number does not have a character in common with any of the previous numbers the program will halt
You are given the following array which is named as numbers
{"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"}

Example runs
Say the following number is given
1

There are no previous numbers so it shares a character will every previous number. So the program will ask for another number, let the following number be given
3

one and three both share the character "e" so this is a valid number. So we given another number, let the following number be given
4

four does not share the "e" common to both one and three so this breaks the pattern so the program now stops
Here is another run with just the output of the program shown
5
15
17
3
7
8
2

This script also had the pattern of numbers with the letter "e"  which caused "two" to break the pattern

Are you sure about requiring the pattern is broken? It's generally frowned upon to require long inputs/outputs in something other than [tag:kolmogorov-complexity]

It can be omitted if it would cause trouble in languages it is good practice to have a message when a program halts though

I will reduce the size of the string to "stopped"

Welcome to PPCG! No offense, but in code golf we generally don't concern ourselves with good practice. It is more useful to focus on the meat of the challenge, in this case determining if the number given fits the pattern. On a similar vein, I'd recommend being able to take the file numbers.txt through STDIN/function argument/etc. instead of explicitly requiring file I/O as that could restrict some languages from competing. Other than that, nice first challenge!

I would also recommend posting future challenges in the sandbox for refinement before posting.

Should the input be echoed as suggested by "Here is another run with just the output of the program shown" or is it enough to just accept input until no overlap remains?

Does "You are given the following array which is named as numbers" imply this is free (no byte cost, eg, it may be an input, in a variable, etc...)?

It may be inputted into the system before the script is run so it would have no bytes cost. You should explain how the numbers array was inputted into the program

I wouldn't recommend specifying a name for the array. There are plenty of languages where numbers isn't a valid variable name. (For example, in Perl, a variable holding an array would need to have a name starting in @.)

Can we stop the program with an error?

The program can end in a error as long as long as no output is written to the screen because of the error

Does STDERR count as screen?

STDERR counts as screen

So...no errors. Got it.

Python 2, 48 46 bytes
Saved two bytes thanks to @ovs!
s=set(''.join(l))
while s:s&=set(l[input()-1])

Try it online!
Renamed numbers to l. If that's not okay then add 10 bytes for l=numbers.


text:
Read a password: on mobile!
Thanks to MD XF's recent challenge, we can now read passwords in many different languages! The problem is, now we need to port our applications to mobile devices, and they do password entry a little differently.
Challenge

Read a string from the keyboard.
Each time a characterk is entered, display it for a short time interval.
After the time interval has passed OR the user has entered another character, replace k with some character c.

Rules

c must be constant; it must be the same character.
c can be any visible character (i.e. it cannot be a newline, space, tab, or unprintable).
c can't be based on any inputted k; c must be defined/constant
before the first k is read.
c must be the same every time the program is run.
c can be one of the values given as k if by accident, as long as all other rules are followed.

You must print k in realtime. As soon as the user enters a new k, you must display it immediately.
k should be visible to the end user before being changed to c; the time interval shall not be less than 0.5 seconds.
k should be replaced by c within a reasonable time; the time interval shall not exceed 5 seconds.
As soon as a new character is entered, whether or not the time interval has expired, you should replace k with c and use the entered key as the new k immediately.

It is acceptable to clear and redraw the screen each time you need to change a character.
You may use any reasonable methods of input and output as long as all other rules are followed.
You may assume that the number of characters inputted is never longer than the terminal/graphical window width.
If using a terminal, your program should terminate after a newline is entered or EOF is reached.
Your program should function as outlined here on both mobile and other environments.

Your program may assume that the input will only contain printable characters (letters, numbers, symbols) and possibly a terminating newline (no backspace, arrow keys, delete, etc).
Your program may terminate when Ctrl+C is pressed.
You may terminate your program by closing a window, if your program launches one.

Scoring
This is code-golf, so the shortest answer in each language wins!
Example
Here is an example of what it should look like. Note this is recorded on a mobile platform, but should also work on a desktop platform.

For those who can see deleted posts, here is the Sandbox post

Which keyboard are you using in the video?

@BetaDecay the notification at the end states zenui keyboard

@BetaDecay It is in fact the ZenUI keyboard. Just curious, or does it matter?

@musicman523 Just curious :)

do i need to redraw/clear the screen? can i just append a new line with the result?

@FelipeNardiBatista The idea is that you are updating the character after a short time (0.5 - 5 seconds), or after the next character is entered. You may either update the screen, or redraw it entirely. (So no, you cannot just append a new line with the result.)

HTML + JavaScript, 20+105 = 125 bytes
<input id=I oninput=v=I.value;s='*'.repeat(l=v.length-1);I.value=s+v[l];clearTimeout(I.t);I.t=setTimeout(`I.value=s+'*'`,1e3)

The delay between the entry of k and the letter becoming * is one second.
JavaScript oninput, Formatted
v=I.value;
s='*'.repeat(l=v.length-1);
I.value=s+v[l];
clearTimeout(I.t);
I.t=setTimeout(`I.value=s+'*'`,1e3)

Test Snippet
Added the ending bracket (>) for better compatibility.

<input id=I oninput=v=I.value;s='*'.repeat(l=v.length-1);I.value=s+v[l];clearTimeout(I.t);I.t=setTimeout(`I.value=s+'*'`,1e3)>

Doesn't seem to terminate though!

@officialaimm The challenge states that only terminal applications need to have a way to terminate them.

Ah, silly me. Sorry.

On my browser I.value => value seems to work fine

Python 3, 186 224 bytes
Works only in windows.
import os,time,msvcrt as m
i=s=x=0;t=time.clock
def v():os.system("cls")
v()
while 1:
 if m.kbhit():
  k=str(m.getch())
  if"\\r"in k:break
  i+=1;x=1;v();print("*"*(i-1)+k[2]);s=t()
 if (t()-s>.6and x):x=0;v();print("*"*i)

Older version(186 bytes): The sleep was mandatory regardless of the speed at which key was pressed.
import os,time,msvcrt
a=k=[];i=0;o=os.system
while 1:
 o("cls")
 if i:print("*"*(i-1)+a[i-1]);time.sleep(.6);o("cls");print("*"*i)
 k=str(msvcrt.getch())
 if"\\r"in k:break
 a+=k[2];i+=1

I don't think this quite meets all the criteria, specifically As soon as a new character is entered, whether or not the time interval has expired, you should replace k with c and use the entered key as the new k immediately. That being said, I can't test it since I don't run Windows, so let me know! You may find this related challenge helpful as a reference

I assumed the replacement from k to c was only graphical (which is fulfilled in my code). Did you also mean to change the stored value of k with c?

Nope, that's all there should be. Your time delay is .6 seconds - what happens if I type in two letters within .1 seconds of each other? Will you still sleep for 1.2 seconds? Again, sorry I can't test this myself - it might be worth posting a video of you running your code!

Modified. The newer version ensures new character can be thrown even before the previous character's time has not been out.

Python 2, 133 bytes
Based on @officialaimm answer.
import time,msvcrt as m
k=T=0
s=p='\r'
while'\r'!=k:
 t=time.time();print s,
 if m.kbhit():k=m.getch();s=p+k;T=t;p+='*'
 if t-T>1:s=p

Woah, 90  bytes less!!! Would vote but my daily limit has been reached. Is there a way to check it(I only have python 3 on my pc)? Btw I dont see no clear screen, how is it managed?

@officialaimm by the \r in the print

I'll post a py3 variant when i get to my classroom

@officialaimm this should work, i'm on linux atm, so i can't test it

I checked it, It's working. (y)

HTML + JavaScript, 115 bytes

<input id=I oninput="setTimeout(g=>g==I.value?I.value=0+g.slice(0,-1):0,1e3,I.value=I.value.replace(/.(?=.)/g,0))">

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Arranging arbitrary shapes to fill a rectangular space
A while ago, I posted a challenge asking to determine whether or not it's possible to arrange arbitrary rectangles to fill a rectangular space, here. That got answers, so clearly it was too easy. (Just kidding, it was fairly challenging, congrats to the answerers :D)
Challenge
Given a bunch of arbitrary shapes (consisting of 1x1 square tiles) (up to 100 with a combined area of at most 1000), can you arrange them to fill a rectangular space, without rotations or reflections?
A shape is valid as input if it has at least 1 tile and all tiles are connected to each other by edges. For example:
Valid:
XXX
X X
XXX

Invalid:
XXX
X
 XX

The shapes will be represented in input by using a non-whitespace character X, spaces, and newlines. Individual shapes will be separated by two newlines (i.e. split on \n\n). You can choose to use LF, CR, or CRLF as a newline. Alternatively, you can choose to use LF or CR as a single newline and CRLF as a double-newline for separating shapes. Please specify in your answer what you choose.
For example, this would be the input format for a 2x2 square and a 3x3 "donut":
XX
XX

XXX
X X
XXX
(Optional trailing newline or double-newline)

The output should be either any truthy value or a consistent falsy value (but not an error). For example, you may output the valid arrangement if one exists or false, but you cannot error if there is no valid arrangement, neither can you output different values for having no valid arrangement.
Test Cases
Test Case 1
XXXX
X  X
XX X

X
X

X

TRUE

Valid Arrangement:
XXXX
XYYX
XXYX

Test Case 2
XXXX
XX

X

FALSE

Test Case 3
XXXXXX
X X  X
X XXX

XX

X
X

X

TRUE

Valid Arrangement:
XXXXXX
XYXZZX
XYXXXA

Test Case 4
XX
X

 X
XX

XXX

X
X
X

TRUE

Valid Arrangement:
XXYZ
XYYZ
AAAZ

Notes

Each shape must be used exactly once in the arrangement
Shapes may not be rotated or reflected
The input can contain multiple identical shapes; in this case, each of those still needs to be used exactly once; that is, if two 5x3 rectangles are given in the input, two 5x3 rectangles must appear in the arrangement

Can the shapes be rotated or reflected?

@xnor For the purposes of this challenge, I will say no. Thanks for noticing that; I always forget to include that. And also thanks for the tag edits :)

I take it each shape must be used exactly once in the tiling? Can the input have multiple identical shapes?

@xnor Sorry for the missed points; yes, each shape may only be used once (hence arrangements over tilings). And yes the input can have multiple identical shapes.

Python 2, 434 bytes
lambda s:F([[' ']*sum(map(lambda s:len(s[0]),s)) for _ in' '*sum(map(len,s))],s)
L=len
R=range
def F(a,s):
 if not s:return len(set(tuple(l)for l in a if'X'in l))==len(set(tuple(l)for l in zip(*a)if'X'in l))==1
 c=s[0];h,w=L(c),L(c[0])
 for i in R(L(a)-h):
	for j in R(L(a[0])-w):
	 T=1;A=[l[:]for l in a]
	 for y in R(h):
		for x in R(w):
		 C=c[y][x]
		 if C>' ':T&=A[y+i][x+j]<'!';A[y+i][x+j]=C
	 r=T and F(A,s[1:])
	 if r:return r

Try it online!
Takes input as a list of lists.
Returns True or None
Assumes that each line in a shape is padded to the length of that shape.
(based on my answer to Do the figures fit?)