*
* B(M, i) * B(N-M, k-i)
* P(X = i) = ---------------------
- * B(N, k)
+ * B(N, k)
*
* where B(a,b) is read "a choose b", and is the number of ways
* to choose b objects out of a possible objects. The formula for it is
* cc cardprobs.c -lm -o cardprobs
*/
#include <math.h>
+#include <signal.h>
#define BASEHAND 7 /* # cards in initial deal */
+static int sx, sk, sM, sN;
+
+void catcher(int sig)
+{
+ putchar('\n');
+ if (sig == SIGFPE)
+ (void) printf("Died while computing H(%d, %d, %d, %d)\n", sx,sk,sM,sN);
+ else
+ (void) printf("Caught signal %d\n", sig);
+}
+
main(argc, argv)
int argc;
char **argv;
(void) printf("%d specials out of %d total; %d turns, %d columns\n",
special, total, turns, columns);
+ (void) signal(SIGFPE, catcher);
+
(void) printf(" | %% chance of this number of specials\n");
(void) printf("Turn | ");
for (j = 0; j < columns; j++)
for (i = 1; i <= turns; i++) {
(void) printf("%2d | ",i);
- for (j = 0; (j < columns) && (j < i + 8) && (j < special+1); j++)
+ for (j = 0; j < columns && j <= i + BASEHAND && j <= special; j++)
{
double p = hyper_prob(j, i + BASEHAND, special, total);
{
double exp(), log_a_choose_b();
+ /* for the signal handler */
+ sx = x;
+ sk = k;
+ sM = M;
+ sN = N;
+
return(exp(log_a_choose_b(M,x) + log_a_choose_b(N-M,k-x) -
log_a_choose_b(N, k)));
}