right, but my point was that if you give it one less data point, i.e.
0,1,2,4,8,16,32,64,128,256
it detects the pattern, but if you tack on the 512 it duffs it.
0,1,2,4,8,16,32,64,128,256
it detects the pattern, but if you tack on the 512 it duffs it.
R code:
solver <- function(x) {
print(x)
if (length(x) == 0 || all(x == 0))
0
else
x[length(x)] + solver(diff(x))
}
solver(c(0,1,2,4,8,16,32,64,128)) #=> 255
solver(c(0,1,2,4,8,16,32,64,128,256)) #=> 512
solver(c(0,1,2,4,8,16,32,64,128,256,512)) #=> 1023
solver(c(0,1,2,4,8,16,32,64,128,26,512,1024)) #=> 2048