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
Solution
let rec factorial n acc =
if n <= 1 then
acc
else
let newAcc = n * acc
factorial (n-1) newAcc
let sumStr num =
let arrStr = num.ToString()
let len = String.length arrStr
let arrNum = Array.create len 0
for i=0 to len-1 do
let numTemp = System.Convert.ToInt32(arrStr.Chars(i).ToString())
arrNum.[i] <- factorial numTemp 1
Array.sum arrNum
let sumTest = [3..99999]
|> Array.map (fun x -> if sumStr x = x then x else 0)
|> Array.sum
- 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
- Find the sum of all numbers which are equal to the sum of the factorial of their digits.
- Note: as 1! = 1 and 2! = 2 are not sums they are not included.
Solution
let rec factorial n acc =
if n <= 1 then
acc
else
let newAcc = n * acc
factorial (n-1) newAcc
let sumStr num =
let arrStr = num.ToString()
let len = String.length arrStr
let arrNum = Array.create len 0
for i=0 to len-1 do
let numTemp = System.Convert.ToInt32(arrStr.Chars(i).ToString())
arrNum.[i] <- factorial numTemp 1
Array.sum arrNum
let sumTest = [3..99999]
|> Array.map (fun x -> if sumStr x = x then x else 0)
|> Array.sum
Comments
Post a Comment