Exemple #1
0
END_TEST

START_TEST(test_visible) {
    ck_assert_int_eq(visible[cardinal(E, N)], R);
    ck_assert_int_eq(visible[cardinal(S, E)], L);
    ck_assert_int_eq(visible[cardinal(N, S)], D);
    ck_assert_int_eq(visible[cardinal(N, N)], U);
}
Exemple #2
0
void objective_function_global_scores(int *n, int *k1, int*k2, int *subset, double *Q) {

  int i, j, m;
  double s;
  int sb1 = (int)sum_binom(*n,*k1);
  int sb2 = (int)sum_binom(*n,*k2);

  m = 0; 
  for (i=1; i<sb1; i++) {
    s = 1.0/(double)(cardinal(subset[i])+1);
    for (j=1; j<sb2; j++) 
      Q[m++] = (s + 1.0/ (double)(cardinal(subset[j])+1)) / (double)(cardinal(subset[i] | subset[j])+2);
    
  }
}
Exemple #3
0
string consolidate(int x, string str) {
    string tmp, atmp;
    string *words;
    int i, y;

    if(x==1 || !str || str == "") return str;
    i = sizeof(words = explode(str, " "));
    if (words[i-1][0]=='(')
     {
      atmp = words[i-1];
      words[i-1]="";
      i -=1;
     }

    if((tmp = lower_case(words[0])) == "a" || tmp == "an" || tmp =="the")
      i = sizeof(words = words[1..i-1]);
    if((y=member_array("of", words))  > 0)
        words[y-1] = pluralize(words[y-1]);
    else words[i-1] =  pluralize(words[i-1]);
    tmp = cardinal(x)+" ";

if (atmp)
     return tmp+implode(words, " ")+" "+atmp;
   return tmp+implode(words, " ");
}
Exemple #4
0
void objective_function_Choquet_coefficients(int *n, double *D) {

  int i, j, m;
  int pow = 1<<*n;

  m = 0;
  for (i=0; i<*n; i++)
    for (j=0; j<pow; j++)
      if(j & 1<<i)
	D[m++] = gamm(cardinal(j)-1, *n);
      
}
Exemple #5
0
int eventReadWatch(){
    int hour, minutes;
    int *time_of_day;
    string hour_string, minute_string;

    time_of_day = SEASONS_D->GetMudTime();
    hour = time_of_day[0];
    minutes = time_of_day[1];

    if(hour > 12) hour -= 12;

    hour_string = cardinal(hour);
    switch(minutes){
        case 0 : minute_string ="o'clock"; break;
        case 1 : minute_string = hour_string;hour_string ="one minute past"; break;
        case 2 : minute_string = hour_string;hour_string ="two minutes past"; break;
        case 3 : minute_string = hour_string;hour_string ="three minutes past"; break;
        case 4 : minute_string = hour_string;hour_string ="four minutes past"; break;
        case 5 : minute_string = hour_string;hour_string ="five past"; break;
        case 6 : minute_string = hour_string;hour_string ="six minutes past"; break;
        case 7 : minute_string = hour_string;hour_string ="seven minutes past"; break;
        case 8 : minute_string = hour_string;hour_string ="eight minutes past"; break;
        case 9 : minute_string = hour_string;hour_string ="nine minutes past"; break;
        case 10 : minute_string = hour_string;hour_string ="ten past"; break;
        case 15 : minute_string = hour_string;hour_string ="quarter past"; break;
        case 45 : minute_string = cardinal(hour+1);hour_string ="quarter of"; break;
        case 50 : minute_string = cardinal(hour+1);;hour_string ="ten of"; break;
        case 55 : minute_string = cardinal(hour+1);hour_string ="five of"; break;
        default : minute_string = cardinal(minutes);break;
    }

    if(minute_string == "thirteen") minute_string = "one";

    write("According to the watch, it is "+hour_string+" "+minute_string+".");

    return 1;
}
Exemple #6
0
string cardinal(int x) {
    string tmp;
    int a;

    if(!x) return "zero";
    if(x < 0) {
        tmp = "negative ";
        x = absolute_value(x);
    }
    else tmp = "";
    switch(x) {
        case 1: return tmp+"one";
        case 2: return tmp+"two";
        case 3: return tmp+"three";
        case 4: return tmp+"four";
        case 5: return tmp+"five";
        case 6: return tmp+"six";
        case 7: return tmp+"seven";
        case 8: return tmp+"eight";
        case 9: return tmp+"nine";
        case 10: return tmp+"ten";
        case 11: return tmp+"eleven";
        case 12: return tmp+"twelve";
        case 13: return tmp+"thirteen";
        case 14: return tmp+"fourteen";
        case 15: return tmp+"fifteen";
        case 16: return tmp+"sixteen";
        case 17: return tmp+"seventeen";
        case 18: return tmp+"eighteen";
        case 19: return tmp+"nineteen";
        case 20: return tmp+"twenty";
        default:
            if(x > 1000000000) return "over a billion";
            else if(a = x /1000000) {
                if(x = x %1000000)
                  return sprintf("%s million %s", cardinal(a),cardinal(x));
                else return sprintf("%s million", cardinal(a));
            }
            else if(a = x / 1000) {
                if(x = x % 1000)
                  return sprintf("%s thousand %s", cardinal(a),cardinal(x));
                else return sprintf("%s thousand", cardinal(a));
            }
            else if(a = x / 100) {
                if(x = x % 100)
                  return sprintf("%s hundred %s", cardinal(a),cardinal(x));
                else return sprintf("%s hundred", cardinal(a));
            }
            else {
                a = x / 10;
                if(x = x % 10) tmp = "-"+cardinal(x);
                else tmp = "";
                switch(a) {
                    case 2: return "twenty"+tmp;
                    case 3: return "thirty"+tmp;
                    case 4: return "forty"+tmp;
                    case 5: return "fifty"+tmp;
                    case 6: return "sixty"+tmp;
                    case 7: return "seventy"+tmp;
                    case 8: return "eighty"+tmp;
                    case 9: return "ninety"+tmp;
                    default: return "error";
                }
            }
    }
}