Skip to content

Instantly share code, notes, and snippets.

@mstahl
Created December 15, 2008 19:50
Show Gist options
  • Save mstahl/36063 to your computer and use it in GitHub Desktop.
Save mstahl/36063 to your computer and use it in GitHub Desktop.
module Main where
import Data.Map as Map
p :: (Ord a, Num t, Num a) => a -> a -> Map (a, a) t -> Map (a, a) t
p k n m =
if member (k, n) m then
m
else if k > n then
insert (k, n) 0 m
else if k == n then
insert (k, n) 1 m
else
let a = p (k + 1) n m
b = p k (n - k) m
in unions [insert (k, n) ((a ! (k + 1, n)) + (b ! (k, n - k))) m, a, b]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment