A Little Python
Posted: Mon Apr 19, 2010 1:52 pm
I feel really slow for this taking as long as it did for me to get the answer. However, I'm still puzzled as to why my C program produced the wrong answer. It looks like it added 1 too many numbers, but isn't xrange(3,11) going to generate all numbers 3-11 inclusive? Here's the code I failed to get the right answer from (the correct answer was the second-to-last value printed to screen rather than the last).
Code: Select all
#include <stdio.h>
int main (int argc, const char * argv[]) {
int array[7];
int y = 0;
int x = 0;
int t = 0;
int r;
int s = 0;
int n = 3;
for (t=0; t<9; t++) {
array[t] = n++;
y = array[t];
x = y * y;
r = x * (x - 1);
s = s + r;
printf("%d\n", s);
}
return 0;
}