Skip to content

Instantly share code, notes, and snippets.

@thesoftwarejedi
Created May 7, 2014 21:19
Show Gist options
  • Save thesoftwarejedi/8cc974d395f4e95fc06c to your computer and use it in GitHub Desktop.
Save thesoftwarejedi/8cc974d395f4e95fc06c to your computer and use it in GitHub Desktop.
You bet using the Martingale strategy:
Whenever you lose a bet, you double the value of the bet for the next round.
Whenever you win, the bet for the next round will be one dollar. You start the round by betting one dollar.
For example, if you start with 20 dollars, and you win the bet in the first round, lose the bet in the next two rounds and then win the bet in the fourth round, you will end up with 20+1-1-2+4 = 22 dollars.
Write a function "go", which takes two arguments:
The 1st argument: integer - the initial money we amount we have when we start the betting.
The 2nd argument: string - The nth character of outcome will be either 'W' (win) or 'L' (lose), denoting the result of the nth round.
Your function should return the amount of money you will have after all the rounds are played as an int.
If at some point you don't have enough money in your account to cover the value of the bet, you must stop and return the sum you have at that point.
No error checking is desired.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment