All Questions
Tagged with memoization functional-programming
9 questions
3
votes
1
answer
319
views
Efficiently calculate value of Pascal's Triangle using memoization and recursion
So reading about functional programming, applications to dynamic programming, and learning Scala. I figured I would try it out with a popular example, Pascal's Triangle, tests against known values ...
6
votes
1
answer
157
views
Generic memoize utility function for pure functions
Given the following generic memoize utility for pure functions with type hints:
...
3
votes
0
answers
116
views
Naive Implementation of A Least Recently Used (LRU) Cache Memoiser
I wrote code to (naively) perform lru memoisation. I tried to write it in a functional programming style, and so did not make use of any global variables.
My Code
...
1
vote
1
answer
39
views
Naive Implementation of Automatic Memoisation
I wrote code to (naively) perform automatic memoisation. I tried to write it in a functional programming style, and so did not make use of any global variables.
My Code
...
2
votes
3
answers
408
views
List of Happy Numbers in scala
Definition of Happy numbers taken from Wikipedia.
A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits ...
5
votes
2
answers
704
views
Calculating the count of integer partitions of a number (uses stateful vectors internally)
I've written a Haskell function to count the number of partitions of an integer - it's basically an implementation of the same algorithm as this one, using Euler's Pentagonal Number Theorem:
$$P(n) = ...
13
votes
1
answer
2k
views
Detecting cycles in a directed graph without using mutable sets of nodes
I recently came across the classic algorithm for detecting cycles in a directed graph using recursive DFS. This implementation makes use of a stack to track nodes currently being visited and an extra ...
4
votes
1
answer
823
views
Universal memoization decorator
I've just written a simple caching / memoization python decorator. It's purpose is to cache what the function returns for all the arguments combinations it's been ever invoked with.
So, if, say, we ...
8
votes
1
answer
1k
views
Generic pure functions memoization
I like to create tools for memoization since it can sometimes be useful. I recently created a generic tool for memoizing the results of pure functions.
Here is an example of how it works:
...