Is it a valid algorithm to win at the casino roulette? I would like to try the following algorithm in order to win in the roulette:


*

*Be an observer until there are 3 same parity numbers in a row ($0$ has no defined parity in this context)

*Once there were achieved 3 numbers with the same parity in a row: init $factor$ to be $1$

*Bet the next number will be the opposite parity if you were wrong double $factor$ and return 3 else goto 1.
Here is a python code for it - which bring profit all the time:
import random

nums = range(37)
bank = 10**10
games = 3000
factor=1
bet_amount=100
next_bet = None
parity_in_row ={"odd":0, "even":0}

for i in xrange(games):
    num = nums[random.randint(0,36)]

    if next_bet == "odd":
        if num % 2 == 1:
            bank += factor*bet_amount
            factor = 1
            next_bet = None
        else:
            bank -= factor*bet_amount
            factor *= 2
    elif next_bet == "even":
        if num % 2 == 0:
            bank += factor*bet_amount
            factor = 1
            next_bet = None
        else:
            bank -= factor*bet_amount
            factor *= 2


    if num > 0 and num % 2 == 0:
        parity_in_row["even"] += 1
        parity_in_row["odd"] = 0
    elif num % 2 == 1:
        parity_in_row["odd"] += 1
        parity_in_row["even"] = 0
    else:
        parity_in_row ={"odd":0, "even":0}

    if parity_in_row["odd"] > 2:
        next_bet = "even"
    elif parity_in_row["even"] > 2:
        next_bet = "odd"
    else:
        next_bet = None

print bank



*

*If I did the calculation correctly the probability to have 4 numbers
in a row with the same parity $ < (1/2-\epsilon)^4 $ [where $\epsilon
   < 1/36$ is a compensation for the probability to achieve $0$].

*Keep doubling $factor$ ensures you will have positive expectation,
right?

*Isn't the probability of getting odd number is $0.5$ ? since
$Prob(odd | even, even, even) = \frac{1}{2}$ ?


Please try to supply a rigorous proof why it is wrong, and try to explain why my python code always return with a positive outcomes 
 A: You missed the fact that your calculation refers to the prior probability of four same-parity numbers in a row, whereas at the moment when you place your bet, you have already observed three of the numbers, hence the probability you are betting on is either the conditional probability of an odd number given that the three previous numbers were odd or  the conditional probability of an even number given that the three previous numbers were even. If you compute that conditional probability correctly, you should find that it is equal to the prior probability that any given spin of the wheel will come up odd (and also equal to the probability that it will come up even).
The rest of your system appears to consist of a double-or-nothing strategy.  If you start with a large enough pile of money (for example, $10^8$ times your initial bet, as shown in your Python code), and you play not too many games (only 3000 in your example), the chances are quite good that this strategy will "work".  But if you are very unlucky, or if you play long enough, you will hit such a bad streak of losses that you will not have enough money left to double your bet after the last loss, and the strategy fails.  In effect, you are risking the loss of 5 to 10 billion units of money in return for a non-quite-certain chance to win 300,000 units of money.
At only 3000 games in each run of your simulation, it may take quite a few runs before you encounter a disastrous outcome, so after a limited number of simulations it may appear to you that this system works well.  But that would only be because you haven't done enough trials to correctly discover the risk.
A: Looks like everyone already told you this--
But, surprisingly enough, each bet in Roulette has the exact same odds to payout ratio, or expected value (EV).
That EV is negative (house edge). So red, black, columns, numbers -- all the same expected return, with the exception of the "sucker's bet" pentagon, which has slightly worse EV than any other bet.
Your system is a combination of believing the roulette wheel has a memory (the 'hot' and 'icy' numbers graphics in Roulette wheels in Vegas are meant to entice suckers with 'systems' that don't work). It doesn't.
You also throw in the Martingale system -- which goes like this. Make a bet -- if you lose, make a larger bet that covers all your losses. Play until you win one time.
The problem with this is that, given you have finite money, and the house has a max bet limit (it does) --- you WILL, at some point, accomplish the unlikely but inevitable feat of losing 8 or 9 times in a row (going from one bet to the max bet) -- and losing a metric S$@! ton of money.
Ultimately, the house has about a 5% edge in Roulette. That means long term, you will average a 95% return on every bet placed on the wheel. 
So a bet of 1000 in the long term average out to 50 lost per bet.
The more bets you make, the more statistically certain this is.
So any system, like the Martingale, that throws increasingly larger sums on the table, averages out to lose increasingly higher amounts overall. 
A: My level is too low to comment BUT I can post this answer so here it goes. 
I see all of you spamming about finite bets and finite money. However, if we do the maths regarding ONLINE roulettes. I came to the following conclusion. 
If you have a starting budget of 20000, the actual chance of losing is very small (not impossible though, but I guess that impossible doesn't exist in statistics). 
Here's why: 
All rolls are completely independent of eachother. The example i'm using has 15 numbers, 7 red, 7 black, 1 green. This effectively means that you have around 46% chance of winning if you bet on red or green. 
Now follow me into some maths. The chance to lose this throw and the next is those two chances multiplied (basic). Your chance to lose is 0.54, so your chance to lose twice in a row is 29%. Now if you keep going like this, let's look at the possibility you'll lose 10 times in a row. this effectively means 0.54^10. We see that this chance is only 0.2%. If the minimum bet is 1, that means (using Martingale of course) you need a minimum of 1023 to be able to bet 10 times on the same color, doubling your bet. 
If you take it even further (saying 13 times not your color in a row), you have 0.03% chance it actually happens and that's something I think we can call statistically negligeable. So that kinda almost solves the finite money stuff. 
Regarding the finite time, some sites offer you an autobet feature. I recommend using that. And for god sakes, don't turn that autobet off when you lose some rounds. Chances are that next round is your round. 
(I know that 0.03% is still a chance to lose. But as you win and earn more money, you'll be able to take on longer 'trains' and eventually this chance will go to its 0 limit.)
Just keep in mind, the house always wins. 
Small sidenote: i'm only talking about online roulettes and I've only played one so far. So the possiblities of me being wrong are pretty big. Just please correct me if i'm wrong.
EDIT:
As commented, there were no real equations although i'm talking about maths. So I'll explain quickly (without too much depth) how I reached certain numbers. 
You have 46% of winning, this is because you have 7/15 chance to win (because all numbers are equally distributed). So 7/15 ≈ 0.46, which means 46%. 
As I said, the chance of losing two rounds in a row is basic Maths. Knowing the fact that two rounds are completely independent of each other, we can just multiply the odds and see the possible chance to lose. (Note that the chance to lose 1 round is ca. 54%). This effectively means 0.54*0.54=29.16%.
Going even further, the chance you lose 10 rounds in a row, would be:
0.54*0.54*0.54*0.54*0.54*0.54*0.54*0.54*0.54*0.54=0.54^10=0.00210 or 0.21%. 
And of course, the further you go, the less chance you have. Taking the 13 rounds example: 0.54^13=0.0003319 or 0.033% chance you'll lose. 
But keep in mind that you'll have to use the martingale system of course, otherwise you'll lose. This means you will need a large enough starting balance, to be able to avoid those nasty trains. 
A: You have discovered the Martingale. It is a perfectly reasonable betting strategy, which was played by Casanova and also by Charles Wells, but unfortunately it doesn't win in the long run. Essentially the strategy is no different from the following idea:
Keep betting. Each time you lose, bet more than your total losses up to now. Since you know that you'll eventually win, you will always end up on top.
Your plan of only betting after getting three the same in a row is a red herring, because spins are independent. It makes no difference if there have already been three in a row. After all, how could it make a difference? If it did, this would imply that the roulette wheel magically possessed some kind of memory, which it doesn't.
There are various explanations for why the strategy doesn't work, among which are: you don't have an infinite amount of money to bet with, the bank doesn't have an infinite amount of money, and you can't play for an infinite amount of time. It's the third of these that is the real problem. Since each bet in roulette has a negative expected value, no matter what you do, you expect to end up with a negative amount of money after any finite number of bets. You can only win if there is no upper limit to the amount of bets you can ever make.
For your last question, the probability of getting an odd number on a real roulette wheel is actually less than $0.5$, because of a 00 on the wheel. But this doesn't change the fact that you have discovered a nice winning strategy; it's just that your strategy can't win (on average) in any finite amount of bets.
