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
Poblem
If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
{20,48,52}, {24,45,51}, {30,40,50}
For which value of p ≤ 1000, is the number of solutions maximised?
Link to original problem description
Solution
open System
let buildArrays xs ys zs limits = seq{
for x in xs do
for y in ys do
if x < y then
for z in zs do
if (x*x + y*y = z*z) then
for limit in limits do
if (x + y + z = limit) then
yield limit, x, y, z}
let First (a,b,c,d) = a
let pyhtosArrays = buildArrays [1..999] [1..999] [1..999] [1..999]
|> Seq.toList
|> List.map (fun x -> First x)
let results = pyhtosArrays |> Seq.countBy id
|> Seq.toList
|> List.sortByDescending snd
Comments
Post a Comment