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 (Improved)
The improvements are minor, but include a smaller corelation matrix amd more concise syntax.
let corrMatrix start last =
seq {for i in start..last do
for j in start..last do
if i< j then yield (i*j)}
let reverse (s:string) = new string(s |> Seq.toArray |> Array.rev)
let palindromes =
(corrMatrix 100 999) |> Seq.filter (fun x -> string x = reverse(string x)) |> Seq.max
Solution (Original)
//function for reversing a string
let reverse (s:string) = new string(s |> Seq.toArray |> Array.rev)
//function to multiple each number in the series by itself, similar to a correlation matrix
let corrMatrix start last =
seq {for i in start..last do
for j in start..last do
yield (i*j)}
//finds the maximum number that is the same forward as backwards
let palindromes =
let lst = corrMatrix 100 999
let comparison = lst |> Seq.filter (fun x -> string x = reverse(string x))
Seq.max comparison
- A palindromic number reads the same both ways.
- The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.
- Find the largest palindrome made from the product of two 3-digit numbers.
Solution (Improved)
The improvements are minor, but include a smaller corelation matrix amd more concise syntax.
let corrMatrix start last =
seq {for i in start..last do
for j in start..last do
if i< j then yield (i*j)}
let reverse (s:string) = new string(s |> Seq.toArray |> Array.rev)
let palindromes =
(corrMatrix 100 999) |> Seq.filter (fun x -> string x = reverse(string x)) |> Seq.max
Solution (Original)
//function for reversing a string
let reverse (s:string) = new string(s |> Seq.toArray |> Array.rev)
//function to multiple each number in the series by itself, similar to a correlation matrix
let corrMatrix start last =
seq {for i in start..last do
for j in start..last do
yield (i*j)}
//finds the maximum number that is the same forward as backwards
let palindromes =
let lst = corrMatrix 100 999
let comparison = lst |> Seq.filter (fun x -> string x = reverse(string x))
Seq.max comparison
Comments
Post a Comment