*
* cc cardprobs.c -lm -o cardprobs
*/
+#include <stdio.h>
#include <math.h>
#include <signal.h>
double hyper_prob();
if (argc == 1) {
- (void) printf("Help for Cardprobs : here's the order of the arguments:\n");
- (void) printf(" # special cards; # total cards; # of turns; \n");
- (void) printf(" # columns.\n");
+ (void) printf("usage: cardprobs M N [t] [c]\n");
+ (void) printf(" M = # special cards\n");
+ (void) printf(" N = # total cards\n");
+ (void) printf(" t = # of turns (optional)\n");
+ (void) printf(" c = columns in the report (optional).\n");
(void) printf("No arguments are optional.\n");
} else {
special = atoi(argv[1]);
total = atoi(argv[2]);
- turns = atoi(argv[3]);
if (total < special) {
(void) printf("Can't have more specials than total cards!\n");
exit(-1);
}
- columns = atoi(argv[4]);
- if (columns > special-1) {
+
+ turns = 20; /* fill a standard screen */
+ if (argc >= 4)
+ turns = atoi(argv[3]);
+ if (turns > total - BASEHAND) {
+ (void) printf("The deck can't last that long!\n");
+ exit(-1);
+ }
+
+ columns = special + 1;
+ if (argc >= 5)
+ columns = atoi(argv[4]);
+ if (columns > special) {
(void) printf("using %d columns because can only have ",special+1);
(void) printf("0 to %d specials\n",special);
columns = special+1;
(void) printf("%2d | ",i);
for (j = 0; j < columns && j <= i + BASEHAND && j <= special; j++)
{
- double p = hyper_prob(j, i + BASEHAND, special, total);
+ int p = (int)rint(hyper_prob(j, i + BASEHAND, special, total) * 100);
- (void) printf("%2.2d ",(int)rint(p * 100));
+ if (p == 0)
+ (void) fputs(" . ", stdout);
+ else
+ (void) printf("%2d ", p);
}
- for (; j < columns; j++)
- (void) printf(" * ");
(void) printf("\n");
}
}