I was exploring Jupyter notebooks , that combines live code, markdown and data, through Microsoft's implementation, known as MS Azure Notebooks , putting together a small library of R and F# notebooks . As Microsoft's FAQ for the service describes it as : ...a multi-lingual REPL on steroids. This is a free service that provides Jupyter notebooks along with supporting packages for R, Python and F# as a service. This means you can just login and get going since no installation/setup is necessary. Typical usage includes schools/instruction, giving webinars, learning languages, sharing ideas, etc. Feel free to clone and comment... In R Azure Workbook for R - Memoisation and Vectorization Charting Correlation Matrices in R In F# Charnownes Constant in FSharp.ipynb Project Euler - Problems 18 and 67 - FSharp using Dynamic Programming
Description
The Fibonacci sequence is defined by the recurrence relation:
F_(n) = F_(n−1) + F_(n−2), where F_(1) = 1 and F_(2) = 1.
Hence the first 12 terms will be:
F_(1) = 1
F_(2) = 1
F_(3) = 2
F_(4) = 3
F_(5) = 5
F_(6) = 8
F_(7) = 13
F_(8) = 21
F_(9) = 34
F_(10) = 55
F_(11) = 89
F_(12) = 144
F_(2) = 1
F_(3) = 2
F_(4) = 3
F_(5) = 5
F_(6) = 8
F_(7) = 13
F_(8) = 21
F_(9) = 34
F_(10) = 55
F_(11) = 89
F_(12) = 144
The 12th term, F_(12), is the first term to contain three digits.
What is the first term in the Fibonacci sequence to contain 1000 digits?
open System.Numerics
//tail-recursion to return Fibonacci based on length of a number's string
let rec fibsRecTailBigIntSingle (x:BigInteger) (y:BigInteger) acc max =
let lenY = (y.ToString()).Length
if lenY >= max then
acc + 1
else
let next = x + y
let item = acc + 1
fibsRecTailBigIntSingle y next item max
let Prob25_1 = fibsRecTailBigIntSingle 1I 1I 1 1000
What is the first term in the Fibonacci sequence to contain 1000 digits?
open System.Numerics
//tail-recursion to return Fibonacci based on length of a number's string
let rec fibsRecTailBigIntSingle (x:BigInteger) (y:BigInteger) acc max =
let lenY = (y.ToString()).Length
if lenY >= max then
acc + 1
else
let next = x + y
let item = acc + 1
fibsRecTailBigIntSingle y next item max
let Prob25_1 = fibsRecTailBigIntSingle 1I 1I 1 1000
Comments
Post a Comment