Friday, February 04, 2011

B/S Bingo

Here's the source. Copy to bsbingo.c and compile with some command such as
cc -o bsbingo bsbingo.c
Then use the commands given under usage (or package them in a little script and put a handy link on your desktop).
The resulting random 5x5 grid is used to relieve the tedium of an otherwise boring meeting.
/***********************************************************/

/* bsbingo
Generates a random bsbingo card.
AOF 4-ii-2011. Copyleft...
Usage:
bsbingo > temp
lpr -o landscape -P <printername> temp
*/

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>

#define N 5  /* number of rows and columns*/
#define PHRASE_LENGTH 18
#define PHRASES {\
" outside the box  ",\
"end of the day    ",\
"   bottom line    ",\
"   iconic         ",\
"   leverage       ",\
\
"core competencies ",\
"   synergy        ",\
"   strategic fit  ",\
"   benchmark      ",\
"   24/7           ",\
\
"   empower        ",\
"   win-win        ",\
"   game plan      ",\
" above our weight ",\
"   bandwidth      ",\
\
"the good of the X ",\
"apples and oranges",\
" green field      ",\
" hopefully        ",\
" shoot ourselves  ",\
\
"game of two 1/2s  ",\
" rennaisance      ",\
"  transparent     ",\
" SWOT(any 2)      ",\
" meltdown         "\
}

void permutation(int* k, int M){
/* places a random permutation of 0,1,2,...,M-1
in the array k[0],...,k[M-1]
*/

int i,j,temp;
int P[M];

for (i=0;i<M;i++){ P[i]=i; }
/* start with the identity */

for (j=0;j<M;j++){
for(i=0;i<M;i++){
if (rand()%2){
/* randomly apply the transposition (ij) or not */
temp = P[j];
P[j] = P[i];
P[i] = temp;
}
}
}

/* copy P to k: */
for (i=0;i<M;i++){
k[i]=P[i];
}
}

void blanks(void){
/* print some spaces */
int i;
for(i=0;i<PHRASE_LENGTH;i++){
printf(" ");
}
}

void solids(void){
/* print some underscores */
int i;
for(i=0;i<PHRASE_LENGTH;i++){
printf("_");
}
}


int main(void)
{
int i,j;
int k[N*N];
char* phrase[N*N] = PHRASES;

srand( time(NULL) );

permutation(k,N*N);

printf("\n\n");

/* print the table, using k to randomise the entries: */


for(j=0;j<N;j++){
printf("_");
solids();
}
printf("\n");

for (i=0;i<N;i++){

printf("|");
for(j=0;j<N;j++){
blanks();
printf("|");
}
printf("\n");

for (j=0;j<N;j++){
printf("|%s", phrase[k[N*i+j]]);
}
printf("|\n");

printf("|");
for(j=0;j<N;j++){
blanks();
printf("|");
}
printf("\n");

for(j=0;j<N;j++){
printf("|");
solids();
}
printf("|\n");



}
printf("\n\n");
return 0;
}

/****************************************************************/

No comments: