#define FOOD_WEIGHTING 19 typedef int bool; #define TRUE 1 #define FALSE 0 #include int food_weighting1(int city_size) { int food_weighting_is_for = 4; /* FOOD_WEIGHTING applies to city with foodbox width of 4 */ int weighting = (food_weighting_is_for * FOOD_WEIGHTING) / (1+city_size); /* If the citysize is 1 we assume it will not be so for long, and so adjust the value a little downwards. */ if (city_size == 1) return ((weighting*3)/4); else return weighting; } #define MAX_CITY_SIZE 50 int food_weighting2(int city_size) { static int cache[MAX_CITY_SIZE]; static bool cache_valid = FALSE; if (!cache_valid) { int i = 0; for (i = 1; i < MAX_CITY_SIZE; i++) { int food_weighting_is_for = 4; /* FOOD_WEIGHTING applies to city with foodbox width of 4 */ int weighting = (food_weighting_is_for * FOOD_WEIGHTING) / (1 + i); /* If the citysize is 1 we assume it will not be so for long, and so adjust the value a little downwards. */ if (i == 1) { weighting = ((weighting * 3) / 4); } cache[i] = weighting; } cache_valid = TRUE; } assert(city_size > 0 && city_size < MAX_CITY_SIZE); return cache[city_size]; } int food_weighting3(int city_size) { return city_size; } int main() { int i,j=0; for(i=0;i<100000000;i++) j+=food_weighting3((i&15)+1); return j; }