Hi all,
So I'm doing the famous (or infamous) Labouchere system simulations in R. I have a function that stops when either the cycle (i.e., 10 - 10 - 10 - 10) is completed OR when you run out of money in you bank(mval). The function works and stops when a cycle is complete but the second part (&& bet < mval) is not working how I wanted it to. It stops the function when a given bet (first number + last number) exceeds the mval. I want this instead to stop when the total amount lost reaches the mval
For example:
When running labouchere(mval = 300) I want 300 to represent the total amount in the bank willing to lose, but this only stops when a specific bet reaches 300. I'm trying to make it stop when the accumulative losses reaches 300.
Created on 2020-07-21 by the reprex package (v0.3.0)
labouchere <- function(mval) {
numbers <- c(10, 10, 10, 10, 10)
earning <- 0
bet <- numbers[1] + numbers[length(numbers)]
counter <- 0
while (length(numbers) >= 1 && bet < mval) {
result <- sample(c(-bet, bet), 1, replace = T, prob = c(0.5,
0.5))
if (result > 0) {
earning <- earning + result
numbers <- numbers[-c(1, length(numbers))]
if (length(numbers) == 1) {
bet <- numbers
}
else {
bet <- numbers[1] + numbers[length(numbers)]
}
}
else {
earning <- earning + result
numbers <- c(numbers, abs(result))
bet <- numbers[1] + numbers[length(numbers)]
}
counter <- counter + 1
}
c(earning, counter)
}
Created on 2020-07-21 by the reprex package (v0.3.0)
Pleaseee any advice??
Thank you!