n <- 0:199
N <- length(n)

fib <- numeric(N) 
pell <- numeric(N)
approx_sqrt2 <- rep(NA, N) 
error <- rep(NA, N) 
accuracy <- integer(N)

fib[1] <- 0 
fib[2] <- 1 
pell[1] <- 0 
pell[2] <- 1

for (i in 3:N) { 
  fib[i] <- fib[i - 1] + fib[i - 2] 
  pell[i] <- 2 * pell[i - 1] + pell[i - 2]
}
sqrt2_true <- sqrt(2)
for (i in 2:(N - 1)) { 
  approx_sqrt2[i] <- pell[i + 1] / pell[i]
  error[i] <- abs(approx_sqrt2[i] - sqrt2_true)
  
  if (!is.na(error[i]) && error[i] == 0) { 
    accuracy[i] <- 16 
  } else if (!is.na(error[i])) { 
    accuracy[i] <- floor(-log10(error[i])) 
  }
}
pelldata <- data.frame( 
  Index = n, 
  Fib = fib, 
  Pell = pell, 
  Approx_Sqrt2 = approx_sqrt2, 
  Diff_from_sqrt2 = round(error, 5),
  Decimal_Accuracy = accuracy
)
pelldata

