Skip to content

Instantly share code, notes, and snippets.

@benjamintanweihao
Created October 19, 2011 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjamintanweihao/1298103 to your computer and use it in GitHub Desktop.
Save benjamintanweihao/1298103 to your computer and use it in GitHub Desktop.
Awesome Continuation Passing.
p(n-1, k) + p(n-1,k-1) + p(n-1,k-2)
#include <stdio.h>
int pascal(int n, int k) {
int aux(int n, int k, int(*c)(int)) {
int c1(int ret1) {
int c2(int ret2) {
int c3(int ret3) {
return c(ret1+ret2+ret3)
}
// Third Recursive
return aux(n-1,k-2,c3)
}
// Second Recursive Call
return aux(n-1, k-1,c2);
}
// First Recursive Call
return aux(n-1,k,c2);
}
// Base Case
if ( k==0 || n ==k ) return c(1) ;
return aux(n-1,k)
int identity(int x) { return x; }
return aux(n,k,identify) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment