Results 1 to 7 of 7

Thread: "Housie" Bingo card generator

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2018
    Posts
    22

    "Housie" Bingo card generator

    Hey guys!

    I'm having real difficulties writing an application to generate "Housie" Bingo cards. A "Housie" bingo card is used in the UK, and is different to the US Bingo card.

    The rules that must be followed when creating a "Housie" Bingo card are as follows:
    Code:
    1. Each ticket comprises of 3 rows of 9 columns (totaling 27 boxes)
    2. Each row must contain 5 numbers
    3. No numbers can be repeated
    4. Each column has a specified range of numbers (e.g. column 1 will contain numbers 1-9, column 2 will contain number 10-19, and so on, until you get to column 9 which will contain numbers 80-90)
    5. No column can be completely blank over the 3 rows (e.g. column 5 rows 1 & 3 can be empty, but it then must have a number in row 2)
    6. All 90 numbers will be used over 6 tickets (but only once)
    I've tried using datatables, jagged arrays, multidimension, arrays List(Of), etc etc. And all my code has been garbage.

    I've searched Google and Youtube extensively and all the results are either for the US Bingo, or written in C/C#/C++ or Java and I cannot understand a single line of that.

    Has anyone got an idea, or knows where I can find something to get me started please?

    Sorry, I don't have any code because it was literally just trying For Loops and that got me nowhere, it either didn't follow the rules (because I don't know how to implement them) or just hung when debugging.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: "Housie" Bingo card generator

    The first step is to stop trying to write code when you don't know what the code has to do. Solve the problem first, then write code to implement the solution. Start by doing it by hand. If you can do it by hand then you can work out what the steps are to do it and then you can write code to implement those steps. It's not always easy to go from just doing it to a formal algorithm because human beings are great at using "fuzzy logic" but that is the actual challenge you have to overcome. Start by just doing it however feels right. Then do it again and again and put some thought into how exactly you're doing it. What actions are you repeating and what decisions are you making? Detail and formalise the steps you perform until you have them to the point that you could hand them to a child with no prior knowledge of the problem and they could follow them to get the right result. Once you're at that stage, you have a working algorithm and THEN you can think about writing code specifically to implement that algorithm. If you have a problem in doing that then you can tell us exactly what step of the algorithm you are having issues with, exactly what you expect to happen and exactly what does happen.

  3. #3
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: "Housie" Bingo card generator

    If your wanting to write this for fun, or just to be able to print a few off, then fine. But if your trying to do this to save money, it won't. Unless you have free paper or ink. If you look online the price is cheap. The reason I know is because I told my son I'd print cards for his club, I'd just got a new colored laser printer. After I did the math, I just bought him 750 cards. lol

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: "Housie" Bingo card generator

    Yeah, I think I would try to break it down into steps, figuring out which rule should be easiest to accomplish first, and then which is easiest second, and so on.
    For instance, you know you want to use each of the 90 numbers once across the six tickets, so you need a list of the numbers available, so you can remove it once you've used it, so you won't choose it again.
    I think since each column has to have at least one number, that would be the first thing I would populate, i.e. for each column pick a random number from the list for that column, and place it in one of the three rows, randomly.
    So, now you should have one number in each column in some random row.
    Secondly, you need five numbers in each row, so now check to see if each row has 5 numbers. If they all have less than 5, you're in good shape. If one has more than five, then pick one of the extra values at random and move it to one of the other rows. Once you have 5 or less in each row, you just need to pick a row that is short, choose one one of the columns at random that has an empty spot in that row, and fill it with a random selection from the list for that column. Do the same with the other row that is short.

    Or you could try to be more efficient.
    You could just try to evenly distribute the numbers from the start, i.e. For the first column, pick one of three rows and place a random number in that row. Then for the second column, choose one of the two rows that doesn't have a number in it yet, and put a random number in that row, then for the third column place a random number in the remaining row. Then repeat for the 4,5, and 6, and again for the 7,8 and 9.

    Now you have selected 9 numbers, and each column contains 1, and each row contains 3.
    Now you just have to select two numbers for each row from the six columns that don't have numbers in them on that row, and put a number in them, and you're done.

    I guess there is a bit more to it than that. You could choose the same random column of the six remaining more often than the others, so run out of numbers for a given column before you make it through all six cards,
    So, for the first row you would choose two columns out of the six available.
    Second row, choose two out of the four columns remaining.
    Third row, choose a random number to put in the two columns left.

    That should give you an even distribution of all the numbers over all the columns and rows over six cards.
    If you can understand what I've said, then it should be fairly easy to work out the code.
    Last edited by passel; Sep 2nd, 2020 at 10:45 PM.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Dec 2018
    Posts
    22

    Re: "Housie" Bingo card generator

    Quote Originally Posted by jmcilhinney View Post
    The first step is to stop trying to write code when you don't know what the code has to do. Solve the problem first, then write code to implement the solution. Start by doing it by hand. If you can do it by hand then you can work out what the steps are to do it and then you can write code to implement those steps. It's not always easy to go from just doing it to a formal algorithm because human beings are great at using "fuzzy logic" but that is the actual challenge you have to overcome. Start by just doing it however feels right. Then do it again and again and put some thought into how exactly you're doing it. What actions are you repeating and what decisions are you making? Detail and formalise the steps you perform until you have them to the point that you could hand them to a child with no prior knowledge of the problem and they could follow them to get the right result. Once you're at that stage, you have a working algorithm and THEN you can think about writing code specifically to implement that algorithm. If you have a problem in doing that then you can tell us exactly what step of the algorithm you are having issues with, exactly what you expect to happen and exactly what does happen.
    As always, the voice of reason!

    In terms of working it out I would go row by row to assign the 5 values, making sure to use all columns at least once.

    The part where each column holds a specific range, I think won't be difficult to implement. It's just creating the grid of 15 valid "cells" within it

    Quote Originally Posted by wes4dbt View Post
    If your wanting to write this for fun, or just to be able to print a few off, then fine. But if your trying to do this to save money, it won't. Unless you have free paper or ink. If you look online the price is cheap. The reason I know is because I told my son I'd print cards for his club, I'd just got a new colored laser printer. After I did the math, I just bought him 750 cards. lol
    I'm literally just trying to accomplish it because in theory it's easy to understand, but in practice I'm finding it impossible to implement. But, my local boozer is just starting to get into running a bingo night, so it would be good to knock something together where they could print their own branded tickets - I'm currently building them a piece of calling software that's branded specifically for them so they can have it on the TVs in the pub. They can get their head office to do any printing etc - but for now, like I say it's just an exercise in trying to implement the logic

    Quote Originally Posted by passel View Post
    Yeah, I think I would try to break it down into steps, figuring out which rule should be easiest to accomplish first, and then which is easiest second, and so on.
    For instance, you know you want to use each of the 90 numbers once across the six tickets, so you need a list of the numbers available, so you can remove it once you've used it, so you won't choose it again.
    I think since each column has to have at least one number, that would be the first thing I would populate, i.e. for each column pick a random number from the list for that column, and place it in one of the three rows, randomly.
    So, now you should have one number in each column in some random row.
    Secondly, you need five numbers in each row, so now check to see if each row has 5 numbers. If they all have less than 5, you're in good shape. If one has more than five, then pick one of the extra values at random and move it to one of the other rows. Once you have 5 or less in each row, you just need to pick a row that is short, choose one one of the columns at random that has an empty spot in that row, and fill it with a random selection from the list for that column. Do the same with the other row that is short.

    Or you could try to be more efficient.
    You could just try to evenly distribute the numbers from the start, i.e. For the first column, pick one of three rows and place a random number in that row. Then for the second column, choose one of the two rows that doesn't have a number in it yet, and put a random number in that row, then for the third column place a random number in the remaining row. Then repeat for the 4,5, and 6, and again for the 7,8 and 9.

    Now you have selected 9 numbers, and each column contains 1, and each row contains 3.
    Now you just have to select two numbers for each row from the six columns that don't have numbers in them on that row, and put a number in them, and you're done.

    I guess there is a bit more to it than that. You could choose the same random column of the six remaining more often than the others, so run out of numbers for a given column before you make it through all six cards,
    So, for the first row you would choose two columns out of the six available.
    Second row, choose two out of the four columns remaining.
    Third row, choose a random number to put in the two columns left.

    That should give you an even distribution of all the numbers over all the columns and rows over six cards.
    If you can understand what I've said, then it should be fairly easy to work out the code.
    I understand your theory. The only issue I think with it is that each row having EXACTLY 5 numbers per row and at least 1 in each column in each ticket carry the same priority.

  6. #6
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: "Housie" Bingo card generator

    Yeah, and the later supposition should take care of that easily. The first pass though you end up with one in each column and three in each row.
    You've distributed nine numbers at this point. You have six more to distribute, two in each row, so the second pass is to do that, so now you've met the at least one in each column, and five in each row.

    The trick is to make sure you continue to distribute the numbers in an even manner, so you don't run out of numbers that go in a column before you reach the last card.
    For instance, assuming the distribution of numbers you mentioned is correct you only have nine numbers for the first column so you know you can't put two numbers from the first columns numbers on each card, that would require 12 numbers. So you will place one number on each card in the first column, which will use up six of your numbers. Three of the cards will have a second number. The total number of rows you're choosing from is 18, so you're distributing 9 numbers into those 18 rows.

    For the middle eight columns, you have 10 numbers to distribute into those 18 rows, and the last column you have 11 numbers to distribute across the 18 rows.

    It seems if you keep track of what row you put a number in, and don't use that same row again until you've distributed numbers to the other rows, it should work out, i.e. you can't put two many numbers in a given row or column, and the five numbers per row will fall out naturally.

    I don't know. If I get interested enough, I might try to code up something for the fun of it, but I don't see it happening right away. Perhaps if I'm looking for something to do over the long labor day weekend coming up (I have Fri and Monday off, without taking any vacation, so its a five day weekend).
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: "Housie" Bingo card generator

    I've written a Bingo card generator before, but in Java...

    http://www.scproject.biz/99_Java_Examples.php (contest 97)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width