The function segmentSegment takes 2 segments (starting and ending points) and computes the shortest distance between them. The function returns a starting and ending point of the shortest segment between the two segments. The function uses a triple type but can be easily rewritten to work with any other type (vector etc).
30 people like thisPosted: 7 years ago by Oldrich Svec
Implements the theory from 'How to write a financial contract' by S.L Peyton Jones and J-M Eber
9 people like thisPosted: 7 years ago by Ademar Gonzalez
This snippet introduces a further subtlety into the previous posting, whereby the intra-hour movement of the hour hand is captured.
0 people like thisPosted: 6 years ago by HP
Simple check if a number is prime. See also http://fssnip.net/2w.
2 people like thisPosted: 6 years ago by d95danb
Written against CruiseControl.NET v1.5. Queries a CruiseControl.NET server for a project list and then computes min, max, average, and standard deviation of the build durations based on the statistics.csv CC.NET maintains.
3 people like thisPosted: 6 years ago by Matt Wilson
Compute the Discrete Fréchet Distance between two arrays (which may be of different lengths). Based on the 1994 algorithm by Thomas Eiter and Heikki Mannila. Not extensively tested, so use at your peril! (This version with some small fixes.)
0 people like thisPosted: 6 years ago by Kit Eason
Small example illustrating how to use Arrays and Sequences to simulate simple Markov chain and evaluate their stationary distribution.
4 people like thisPosted: 5 years ago by Mathias Brandewinder
An implementation of John D. Cook's algorithm for fast-finding perfect squares: http://www.johndcook.com/blog/2008/11/17/fast-way-to-test-whether-a-number-is-a-square/
1 people like thisPosted: 5 years ago by Kit Eason
Square root for integral types
5 people like thisPosted: 5 years ago by ildjarn
let erfinv x = let mutable p = 0.0 let mutable w = -log((1.0-x)*(1.0+x)) // corrected sign if w < 5.000000 then w <- w - 2.500000 p <- 2.81022636e-08 p <- 3.43273939e-07 + p*w p <- -3.5233877e-06 + p*w p <- -4.39150654e-06 + p*w p <- 0.00021858087 + p*w p <- -0.00125372503 + p*w p <- -0.00417768164 + p*w p <- 0.246640727 + p*w p <- 1.50140941 + p*w else w <- sqrt w - 3.000000 p <- -0.000200214257 p <- 0.000100950558 + p*w p <- 0.00134934322 + p*w p <- -0.00367342844 + p*w p <- 0.00573950773 + p*w p <- -0.0076224613 + p*w p <- 0.00943887047 + p*w p <- 1.00167406 + p*w p <- 2.83297682 + p*w p*x
2 people like thisPosted: 5 years ago by Clever people
Estimate the value of PI using a Monte Carlo simulation.
5 people like thisPosted: 5 years ago by Phillip Trelford
Compute the great circle distance of 2 points
3 people like thisPosted: 4 years ago by Samuel Bosch
Simple and a more optimized implementation of the azimuthal equidistant projection. Input is expected in degrees.
3 people like thisPosted: 4 years ago by Samuel Bosch
A generic numeral G. It allows writing functions for arbitrary numeric type. The transformation is an efficient one, because it is implemented explicitly for every type. It combines the type classes technique of FsControl (https://github.com/gmpl/FsControl and http://nut-cracker.azurewebsites.net/typeclasses-for-fsharp) with numeric literals. But FsControl is removed to completely avoid unnecessary function calls.
4 people like thisPosted: 4 years ago by Daniel Fabian (@iceypoi)
Function that converts numeric types using type inference. This is meant to complement the generic number literal G in helping to write generic numeric code. The implementation is similar to the generic number literal snippet. See http://fssnip.net/mv/
1 people like thisPosted: 2 years ago by Sami Perttu
Lagrange's interpolation formula
5 people like thisPosted: 1 year ago by Ivan Padron
Returns the pascal triangle in a 2D list . This snippet computes rows translating the 'visual' method taught at school into Lists and the usage of map2 function. It takes almost 5 seconds to compute 5000 rows.
20 people like thisPosted: 7 years ago by Horacio Nuñez
This is a response to a Google interview question that someone encountered. A friend of mine was recently hired there and I've heard some thrilling stories of their interview process. So every now and then, I plan to code up a response to one of the hoards of interview questions they have.
0 people like thisPosted: 6 years ago by Antwan "A-Dubb" Wimberly
Basic prime number generator
1 people like thisPosted: 6 years ago by d95danb
Implements a bijective mapping between permutations and pairs of standard Young tableaux, both having the same shape. http://en.wikipedia.org/wiki/Robinson%E2%80%93Schensted_correspondence
4 people like thisPosted: 6 years ago by Ademar Gonzalez
A vector type with units of measure built on top of XNA's Vector3. Not complete, the point is mainly to show how to use generic units of measure to adapt an existing type.
9 people like thisPosted: 6 years ago by Johann Deneux
Andrew's Monotone Chain Convex Hull algorithm: given points in 2 dimensions, determine their convex hull by constructing the upper and lower hull.
6 people like thisPosted: 6 years ago by Mathias Brandewinder
Simple walkthrough that demonstrates how to estimate the value of PI using Monte Carlo simulation. A few holes need to be filled in and then you can run & parallelize the sample!
4 people like thisPosted: 5 years ago by Tomas Petricek
This snippet adds the 'GetSlice' operation to Math.Net vector and matrix types. This makes it possible to get sub-vectors and sub-matrices using the convenient syntax (For vectors 'vect.[start .. end]` or 'vect.[start ..]' and for matrices 'mat.[r1 .. r2, c1 .. c2]' and similar).
9 people like thisPosted: 5 years ago by Tomas Petricek
A quick exploration of the rather useless question "how does the density of the product of 2 sparse matrices look like?"
0 people like thisPosted: 5 years ago by Mathias Brandewinder
Defines the operator /% as DivRem for int, int64 and bigint.
5 people like thisPosted: 5 years ago by Diego Frata
Density-based spatial clustering of applications with noise (DBSCAN) is a data clustering algorithm. For more information see http://en.wikipedia.org/wiki/DBSCAN. The implementation is based on the pseudocode in the article and the following C# code http://www.c-sharpcorner.com/uploadfile/b942f9/implementing-the-dbscan-algorithm-using-C-Sharp/ The implementation is not very functional but does the job. Added pwd by ignorance, the password is "fssnip" (without quotes)
1 people like thisPosted: 4 years ago by Samuel Bosch
Convert negative and positive integers to a positive value by using an overlap and interleave scheme (more info: http://en.wikipedia.org/wiki/Golomb_coding).
1 people like thisPosted: 4 years ago by Samuel Bosch
Simple version of the azimuthal equidistant projection (see also http://fssnip.net/lA) but with measures. This avoids mixing of degrees and radians and longitudes/x and latitudes/y
2 people like thisPosted: 4 years ago by Samuel Bosch
A more idiomatic definition of a Rational type with custom operators.
1 people like thisPosted: 3 years ago by Tomas Petricek
Euler method is a first-order numerical procedure for solving ordinary differential equations (ODEs) with a given initial value.
1 people like thisPosted: 1 year ago by Ivan Padron
Function to get all possible combinations of list items. There are some Euler problems (like 77 & 78) to get total amounts. But e.g. for some card game implementations you will need the real items.
3 people like thisPosted: 11 months ago by Tuomas Hietanen