Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
9
Task/Forward-difference/F-Sharp/forward-difference.fs
Normal file
9
Task/Forward-difference/F-Sharp/forward-difference.fs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
let rec ForwardDifference input n =
|
||||
match n with
|
||||
| _ when input = [] || n < 0 -> [] // If there's no more input, just return an empty list
|
||||
| 0 -> input // If n is zero, we're done - return the input
|
||||
| _ -> ForwardDifference // otherwise, recursively difference..
|
||||
(input.Tail // All but the first element
|
||||
|> Seq.zip input // tupled with itself
|
||||
|> Seq.map (fun (a, b) -> b-a) // Subtract the i'th element from the (i+1)'th
|
||||
|> Seq.toList) (n-1) // Make into a list and do an n-1 difference on it
|
||||
Loading…
Add table
Add a link
Reference in a new issue