A few weeks ago my daughter’s class was gearing up to celebrate the Thanksgiving Holiday, and I was asked to help prepare some “holiday bingo cards” for the kid’s party. Naturally, I wrote a program in R for the job! (I know, I know, Maslow’s hammer)
Since I learned a few R tricks for making a grid and placing text, and since today is the first day of the Hour of Code, I’ve decided to release the code;-)
The 13 lines (excluding comments) of code below will produce 25 random Festivus Bingo Cards and write them out to a single pdf file for easy printing. You supply the Festivus Nog.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# file to make random holiday bingo boards in R. . . # How many different cards do you want to make? num.unique.bingo.cards<-25 # 25 words to populate the board with: my.words<-toupper(c("Seinfeld", "Costanza", "Festivus", "Kramer", "pole", "Grievances", "Strength", "meatloaf", "wrestling ", "Miracle", "Elaine", "Jerry","George", "Dinner", "NBC","December", "Sitcom", "1997", "two-face", "donation", "Kruger", "Flask", "Strike", "Submarine", "Gwen")) # Put it all in a single pdf file for easy printing! pdf("bingo.cards.pdf", width=7.5, height=7.5) for(i in 1:num.unique.bingo.cards){ # Build a 5 x 5 Matrix for the Grid; ignore the warnings:-) m <- matrix(0:1, nrow=5, ncol=5) image(m, col=c("darkgreen", "red"), xaxt="n", yaxt="n", main="Festivus Bingo") the.vals<-c(0, .25, .5, .75, 1,1, .75, .5, .25, 0) x.y.vals<-combn(the.vals, 2) the.coords<-unique(t(x.y.vals)) word.sample<-sample(my.words) text(the.coords, word.sample, col="white", cex=.75) } dev.off() |