Snippets tagged Recursion
Filtering lists
Two functions showing how to filter functional lists using the specified predicate. First version uses naive recursion and the second one is tail-recursive using the accumulator parameter.
39 people like this
Posted: 1 years ago by Tomas PetricekRandom walk
Create sequence of floating point values generated by random walk process. Functional solution using sequence expressions and yield! construct in a tail-call position.
22 people like this
Posted: 1 years ago by Tomas PetricekRecursive functions
Show's how to define a recursive function that will calculate a fibonacci number.
9 people like this
Posted: 1 years ago by Robert PickeringContinuation-Passing Mnemonics
Continuations provide a means whereby heap space can be traded for stack depth (heap space being generally more plentiful than stack depth). They are especially useful where tail recursion is not possible. Here are a couple of simple continuation examples that can be extended to cover more complex scenarios.
64 people like this
Posted: 1 years ago by Neil CarrierProjecting lists
Three functions showing how to implement projection for functional lists. First version uses naive recursion and the second one is tail-recursive using the accumulator parameter. The third version extends this with continuation passing.
43 people like this
Posted: 1 years ago by Tomas PetricekMemoization and Tail Recursive Function
Hi, I expressed Memoization and Memoization Tail Recursive on the functions. I hope something useful.
12 people like this
Posted: 1 years ago by zeclFunction to generate all possible combinations where combination "ab" != "ba"
Function to generate all possible combinations where combination "ab" is different then "ba"
5 people like this
Posted: 1 years ago by Ankur DhamaProject Euler #182
The RSA encryption is based on the following procedure: Generate two distinct primes p and q. Compute n=pq and phi=(p-1)(q-1). Find an integer e, 1<e<phi, such that gcd(e,phi)=1. There exist values of e and m such that m^(e) mod n=m. We call messages m for which m^(e) mod n=m unconcealed messages. Choose p=1009 and q=3643. Find the sum of all values of e, so that the number of unconcealed messages for this value of e is at a minimum.
20 people like this
Posted: 1 years ago by Natallie Baikevich
Split a list
Three ways to split a list in half (but not necessarily in the middle). A forth version added that's very short and should be fast, as we only use List.fold. New champ found.
48 people like this
Posted: 1 years ago by Dmitri PavlenkovIRC Jokes
Simple snippet that demonstrates recursively defined discriminated unions, the Y combinator (for encoding recursive functions) and recursive processing of tree-like structures
5 people like this
Posted: 1 years ago by Daniel JacksonFactorial using Int64, Double and BigInteger
Recursive Factorial using Int64, Double and BigInteger with execution time.
0 people like this
Posted: 1 years ago by Carlos QuintanillaCombinatorial functions
Here is my F# take on some combinatorial functions from the book "Introduction to Functional Programming" by Richard Bird and Philip Wadler.
5 people like this
Posted: 1 years ago by Cesar MendozaAbstraction of the "tail-recursive loop" pattern
A novel, due to performance inadequacy, abstraction of the "tail-recursive loop" pattern. Approaching what a built-in language feature might look like.
3 people like this
Posted: 1 years ago by Stephen SwensenEuler #5
Euler #5 solution
3 people like this
Posted: 8 months ago by Michael FalangaRandom Subset
A function that takes a random subset from a seq<'T>.
0 people like this
Posted: 5 months ago by Taha Hachana