initial commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
module _101
|
||||
|
||||
open common
|
||||
open System
|
||||
|
||||
let leGrange points x =
|
||||
points
|
||||
|> Seq.mapi (fun j (xj,y) ->
|
||||
y * (
|
||||
points
|
||||
|> Seq.mapi (fun k (xk,_) ->
|
||||
if (j = k) then 1.0 else
|
||||
(x - xk) / (xj - xk)
|
||||
)
|
||||
|> Seq.fold (*) 1.0
|
||||
)
|
||||
)
|
||||
|> Seq.sum
|
||||
|
||||
let rec polynomialGen p x =
|
||||
if p = 0 then 1L else
|
||||
let rest = polynomialGen (p-1) x
|
||||
let this = int64 (Math.Pow(float x, float p))
|
||||
if p % 2 = 0 then
|
||||
rest + this
|
||||
else
|
||||
rest - this
|
||||
|
||||
let poly10 = polynomialGen 10
|
||||
|
||||
let cube x =
|
||||
int64 (Math.Pow(float x,3.0))
|
||||
|
||||
let funTup f n = (n, f n)
|
||||
|
||||
let sumOfFITsOfBOPs =
|
||||
let leGrangeTermChecker f seqLimit =
|
||||
[1..seqLimit]
|
||||
|> Seq.map (fun n -> (float n, float (f n)))
|
||||
|> (fun points ->
|
||||
let nth = points |> Seq.nth (seqLimit - 1) |> snd
|
||||
let pointsMinusLast = points |> Seq.take (seqLimit - 1)
|
||||
let nthLegrange = leGrange pointsMinusLast (float seqLimit)
|
||||
|
||||
(int64 nth, int64 nthLegrange)
|
||||
)
|
||||
|
||||
allIntegers |> Seq.skip 2
|
||||
|> Seq.map (leGrangeTermChecker poly10)
|
||||
|> Seq.take 11
|
||||
//|> Seq.takeWhile (fun (nth,nthLeGrange) -> .Abs( nth - nthLeGrange) < 2)
|
||||
|> Seq.toArray
|
||||
//|> Array.map snd
|
||||
//|> Array.sum
|
||||
Reference in New Issue
Block a user