Created
February 5, 2011 23:45
-
-
Save codegoalie/812932 to your computer and use it in GitHub Desktop.
Computes pseudo-random bingo cards to fill with a list of items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "How many players?" | |
players = gets.chomp.to_i | |
puts "How many items?" | |
items = gets.chomp.to_i | |
(1..players).each do |i| | |
puts "card #{i}" | |
card = Array.new | |
(1..5).each do |row| | |
print " " | |
(1..5).each do |col| | |
if(row == 3 && col == 3) | |
print " F " | |
else | |
begin | |
next_num = rand(items) + 1 | |
end while !card.index(next_num).nil? | |
card << next_num | |
print " " if next_num < 10 | |
print next_num | |
print " " | |
end | |
end | |
print "\n" | |
end | |
print "\n" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
equire 'prawn' | |
require 'spreadsheet' | |
items = [] | |
Spreadsheet.open('bingo_items.xls').worksheet(0).each do |row| | |
items << row[0] unless row[0].nil? | |
end | |
#items.each { |i| puts i } | |
puts "How many players?" | |
players = gets.chomp.to_i | |
Prawn::Document.generate 'bingo_cards.pdf' do | |
(1..players).each do |current_player| | |
font_size 22 | |
text "Commercial Bingo", :align => :center | |
font_size 18 | |
text "Super Bown XLVI", :align => :center | |
move_down 15 | |
font_size 16 | |
text "Player #{current_player}" | |
font_size 14 | |
move_down 30 | |
card = [[ "B", "I", "N", "G", "O"]] | |
(1..5).each do |row| | |
row_items = [] | |
(1..5).each do |col| | |
if(row == 3 && col == 3) | |
row_items << "FREE SPACE" | |
else | |
begin | |
next_num = rand(items.length) | |
end while card.flatten.include?(items[ next_num ]) | |
row_items << items[next_num] | |
end | |
end | |
card << row_items | |
end | |
move_down 50 | |
table card do | |
width = 500 | |
cells.valign = :center | |
cells.align = :center | |
row(0).font_style = :bold | |
row(0).size = 16 | |
#free space | |
row(3).column(2).border_width = 2 | |
row(3).column(2).font_style = :bold | |
end | |
start_new_page unless current_player == players | |
end | |
end |
Another year, another Bingo game. This year, I improved the script to generate PDFs of the bingo cards. Here's how it works: First a list of items which might appear in a commercial are imported from an Excel spreadsheet. Simply put an xls file named 'bingo_items.xls' in the same folder as the script listing the times in the first column. Second, the script will prompt you for the number of players. That's it. You will get a PDF named 'bingo_cards.pdf' output in the same directory with as many pages as you selected players. The script still prevents duplicates from appearing on the same sheet and it will print out this (2012) year's Super Bowl number.
Happy Bingo-ing!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: This does not generate typical bingo cards with number ranges for each column. I wrote this to generate cards for "Commercial Bingo" for the Super Bowl. I wrote up a list of 35 things to look for in commercials and I needed to randomize the placement of the items on some cards for our guests.