Name:
Anonymous
2011-05-24 17:46
$ cat bc2.c; gcc -O3 -Wall bc2.c -o bc2; time ./bc2
#include <stdio.h>
#include <stdint.h>
#define BOWLS 40
#define ORANGES 9
int solutions = 0;
void rec(int oranges, int pos, int64_t bowls, int64_t distances)
{
int i;
if (pos >= BOWLS) return;
rec(oranges, pos+1, bowls, distances);
bowls |= (int64_t)1<<pos;
oranges--;
for(i = 0; i < pos; i++) {
if (bowls & (int64_t)1<<i) {
int dist = pos - i;
if (distances & (int64_t)1<<dist) return;
distances |= (int64_t)1<<dist;
}
}
if (!oranges) {
solutions++;
return;
}
rec(oranges, pos+1, bowls, distances);
}
int main()
{
rec(ORANGES, 0, 0, 0);
printf("%d\n", solutions);
return 0;
}
0
real 0m0.356s
user 0m0.355s
sys 0m0.001s
Nice challenge bro, took all of 5 minutes.