Q:

Recursion in Python for a daily coding challenge

I am trying to solve some of the coding challenges that I find online.  However I was stopped by the below problem.  I tried to solve it using recursion but I feel I am missing a very important concept in recursion.  My code works for all of the below examples except the last one it will break down. 
Can someone point to me the mistake that I made in this recursion code?  Or maybe guide me through solving the issue? 
I know why my code breaks but I don't know how to get around the "pass by object reference" in Python which I think creating the bigger problem for me. 
The coding question is:

On a mysterious island there are creatures known as Quxes which come in three colors: red, green, and blue.  One power of the Qux is that if two of them are standing next to each other, they can transform into a single creature of the third color. 
Given N Quxes standing in a line, determine the smallest number of them remaining after any possible sequence of such transformations. 
For example, given the input ['R', 'G', 'B', 'G', 'B'], it is possible to end up with a single Qux through the following steps:
        Arrangement       |   Change
----------------------------------------
['R', 'G', 'B', 'G', 'B'] | (R, G) -> B
['B', 'B', 'G', 'B']      | (B, G) -> R
['B', 'R', 'B']           | (R, B) -> G
['B', 'G']                | (B, G) -> R
['R']                     |
________________________________________

My code is:
class fusionCreatures(object):
    """Regular Numbers Gen.
    """

    def __init__(self , value=[]):
        self.value = value
        self.ans = len(self.value)
        

    def fusion(self, fus_arr, i):
        color = ['R','G','B']
        color.remove(fus_arr[i])
        color.remove(fus_arr[i+1])
        fus_arr.pop(i)
        fus_arr.pop(i)
        fus_arr.insert(i, color[0])
        return fus_arr
        
        
    def fusionCreatures1(self, arr=None):
        # this method is to find the smallest number of creature in a row after fusion 
        if arr == None:
            arr = self.value
        for i in range (0,len(arr)-1):
            #print(arr)
            if len(arr) == 2 and i >= 1 or len(arr)<2:
                break
            if arr[i] ! = arr[i+ 1]:
                arr1 = self.fusion(arr, i)
                testlen = self.fusionCreatures1(arr)
                if len(arr) < self.ans:
                    self.ans = len(arr)
        return self.ans

Testing array (all of them work except the last one):
t1 = fusionCreatures(['R','G','B','G','B'])
t2 = fusionCreatures(['R','G','B','R','G','B'])
t3 = fusionCreatures(['R','R','G','B','G','B'])
t4 = fusionCreatures(['G','R','B','R','G'])
t5 = fusionCreatures(['G','R','B','R','G','R','G'])
t6 = fusionCreatures(['R','R','R','R','R'])
t7 = fusionCreatures(['R', 'R', 'R', 'G', 'G', 'G', 'B', 'B', 'B'])

print(t1.fusionCreatures1())
print(t2.fusionCreatures1())
print(t3.fusionCreatures1())
print(t4.fusionCreatures1())
print(t5.fusionCreatures1())
print(t6.fusionCreatures1())
print(t7.fusionCreatures1())

A:

I'll start by mentioning that there is a deductive approach that works in O(n) and is  detailed in this blog post.  It boils down to checking the parity of the counts of the three types of elements in the list to determine which of a few fixed outcomes occurs. 
You mention that you'd prefer to use a recursive approach, which is O(n!).  This is a good start because it can be used as a tool for helping arrive at the O(n) solution and is a common recursive pattern to be familiar with. 
Because we can't know whether a given fusion between two Quxes will ultimately lead to an optimal global solution we're forced to try every possibility.  We do this by walking over the list and looking for potential fusions.  When we find one, perform the transformation in a new list and call fuse_quxes on it.  Along the way, we keep track of the smallest length achieved. 
Here's one approach:
def fuse_quxes(quxes, choices="RGB"):
    fusion = {x[:-1]: [x[-1]] for x in permutations(choices)}

    def walk(quxes):
        best = len(quxes)

        for i in range(1, len(quxes)):
            if quxes[i-1] ! = quxes[i]:
                sub = quxes[:i-1] + fusion[quxes[i-1], quxes[i]] + quxes[i+1:]
                best = min(walk(sub), best)

        return best

    return walk(quxes)

This is pretty much the direction your provided code is moving towards, but the  implementation seems unclear.  Unfortunately, I don't see any single or quick fix.  Here are a few general issues:

Putting the fusionCreatures1 function into a class allows it to mutate external state, namely self.value and self.ans.  self.value in particular is poorly named and difficult to keep track of.  It seems like the intent is to use it as a reference copy to reset arr to its default value, but arr = self.value means that when fus_arr is mutated in fusion(), self.value is as well.  Everything is pretty much a reference to one underlying list. 
Adding slices to these copies at least makes the program easier to reason about, for example, arr = self.value[:] and fus_arr = fus_arr[:] in the fusion() function.  In short, try to write pure functions. 
self.ans is also unclear and unnecessary; better to keep the result value relegated to a local variable within the recursive function. 
It seems unnecessary to put a stateless function into a class unless it's a purely static method and the class is acting as a namespace. 
Another cause of cognitive overload are branching statements like if and break.  We want to minimize the frequency and nesting of these.  Here is fusionCreatures1 in pseudocode, with annotations for mutations and complex interactions:
def fusionCreatures1():
    if ...
        read mutated global state
    for i in len(arr):
        if complex length and index checks:
            break
        if arr[i] ! = arr[i+ 1]:
            impure_func_that_changes_arr_length(arr)
            recurse()
            if new best compared to global state:
                mutate global state

You'll probably agree that it's pretty difficult to mentally step through a run of this function. 
In fusionCreatures1(), two variables are unused:
        arr1 = self.fusion(arr, i)
        testlen = self.fusionCreatures1(arr)

The assignment arr1 = self.fusion(arr, i) (along with the return fus_arr) seems to indicate a lack of understanding that self.fusion is really an in-place function that mutates its argument array.  So calling it means arr1 is arr and we have another aliased variable to reason about. 
Beyond this, neither arr1 or testlen are used in the program, so the intent is unclear. 
A good linter will pick up these unused variables and identify most of the other complexity issues I've mentioned. 
Mutating a list while looping over it is usually disastrous.  self.fusion(arr, i) mutates arr inside a loop, making it very difficult to reason about its length and causing an index error when the range(len(arr)) no longer matches the actual len(arr) in the function body (or at least necessitating an in-body precondition).  Making self.fusion(arr, i) pure using a slice, as mentioned above, fixes this problem but reveals that there is no recursive base case, resulting in a stack overflow error. 
Avoid variable names like arr, arr1, value unless the context is obvious.  Again, these obfuscate intent and make the program difficult to understand. 

Some minor style suggestions:

Use snake_case per PEP-8.  Class names should be TitleCased to differentiate them from functions.  No need to inherit from object--that's implicit. 
Use consistent spacing around functions and operators: range (0,len(arr)-1): is clearer as range(len(arr) - 1):, for example.  Use vertical whitespace around blocks. 
Use lists instead of typing out t1, t2, ... t7. 
Function names should be verbs, not nouns.  A class like fusionCreatures with a method called fusionCreatures1 is unclear.  Something like QuxesSolver.minimize(creatures) makes the intent a bit more obvious. 

As for the solution I provided above, there are other tricks worth considering to speed it up.  One is memoization, which can help avoid duplicate work (any given list will always produce the same minimized length, so we just store this computation in a dict and spit it back out if we ever see it again).  If we hit a length of 1, that's the best we can do globally, so we can skip the rest of the search. 
Here's a full runner, including the linear solution translated to Python (again, defer to the blog post to read about how it works):
from collections import defaultdict
from itertools import permutations
from random import choice, randint

def fuse_quxes_linear(quxes, choices="RGB"):
    counts = defaultdict(int)

    for e in quxes:
        counts[e] += 1

    if not quxes or any(x == len(quxes) for x in counts.values()):
        return len(quxes)
    elif len(set(counts[x] % 2 for x in choices)) == 1:
        return 2

    return 1

def fuse_quxes(quxes, choices="RGB"):
    fusion = {x[:-1]: [x[-1]] for x in permutations(choices)}

    def walk(quxes):
        best = len(quxes)

        for i in range(1, len(quxes)):
            if quxes[i-1] ! = quxes[i]:
                sub = quxes[:i-1] + fusion[quxes[i-1], quxes[i]] + quxes[i+1:]
                best = min(walk(sub), best)

        return best

    return walk(quxes)

if __name__ == "__main__":
    tests = [
        ['R','G','B','G','B'],
        ['R','G','B','R','G','B'],
        ['R','R','G','B','G','B'],
        ['G','R','B','R','G'],
        ['G','R','B','R','G','R','G'],
        ['R','R','R','R','R'],
        ['R', 'R', 'R', 'G', 'G', 'G', 'B', 'B', 'B']
    ]

    for test in tests:
        print(test, "=>", fuse_quxes(test))
        assert fuse_quxes_linear(test) == fuse_quxes(test)

    for i in range(100):
        test = [choice("RGB") for x in range(randint(0, 10))]
        assert fuse_quxes_linear(test) == fuse_quxes(test)

Output:
['R', 'G', 'B', 'G', 'B'] => 1
['R', 'G', 'B', 'R', 'G', 'B'] => 2
['R', 'R', 'G', 'B', 'G', 'B'] => 2
['G', 'R', 'B', 'R', 'G'] => 1
['G', 'R', 'B', 'R', 'G', 'R', 'G'] => 2
['R', 'R', 'R', 'R', 'R'] => 5
['R', 'R', 'R', 'G', 'G', 'G', 'B', 'B', 'B'] => 2

