/* You have b identical crystal balls. There is a high rise with a
 * f floors. One of the floors could be critical. When a crystal ball is
 * dropped from the critical floor or from a higher floor the ball breaks. You
 * need to find the critical floor with the minimum number of experiments in the
 * worst case. Each drop is counted as one experiment regardless of whether the
 * ball breaks or not.
 *
 * If you have only one ball, you must start your experiments from the first
 * floor. In the worst case you will end up performing an experiment every floor
 * just to find out that there is no critical floor. Given one ball the minimum
 * number of experiments required in the worst case is f.
 *
 * A program that reads the number of floors f and the number of
 * b balls, and prints out the minimum number of experiments required.
 */
#include <stdio.h>

int comp_floors(int exprs, int balls)
{
  if (balls == 0)
    return 0;
  if (exprs == 0)
    return 0;
  return comp_floors(exprs - 1, balls) + comp_floors(exprs - 1, balls - 1) + 1;
}

int main()
{
  int floors, exprs, balls;
  printf("Enter number of floors followed by number of balls: ");
  if (scanf("%d %d", &floors, &balls) != 2) {
    printf("ERROR: cannot read input!\n");
    return -1;
  }
  for (exprs = 0; 1; exprs++) {
    if (comp_floors(exprs, balls) >= floors)
      break;
  }
  printf("Required %d exprs\n", exprs);
  return 0;
}
