Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

hay look at my recursive pow

Name: Anonymous 2009-03-04 20:14


#include <stdio.h>
#include <stdlib.h>

unsigned long long rpow(int n, int p) {
  return p ? p==1 ? n : n * rpow(n,p-1) : 1;
}

int main(int argc, char **argv) {
  if(argv[1])
    if(argv[2]) {
      int n = atoi(argv[1]);
      int p = atoi(argv[2]);
      printf("%llu\n",rpow(n,p));
    }
  return 0;
}

Name: Anonymous 2009-03-12 23:29

>>138
Wow you are the biggest idiot ever. Let me model this a bit more clearly so you're retard brain can handle it.

Before you use the pow function, you have to load or generate the table. Never did I say that you would do this more than once or every time you call pow. The point is, the work you do in loading or generating the table will not be paid off by a single call to pow, you will have to an equivalent amount of work in pow calls as you did in loading the table for the amortization argument to work at all.

I suggest you take some time off work/school and re-learn amortized analysis. You definitely wouldn't cut it in the real world. Stick to writing and re-writing factorial and Fibonacci functions.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List