Gossamer Forum
Home : General : Perl Programming :

Bingo system

Quote Reply
Bingo system
Working on on nothing i was doing a card print for bingo.

so its like 10.000 cards every card with 25 numbers (single numbers in other words they cant repeat), 5 coluns per card.

the numbers that will be sorted 1 to 75

so i did that.

#!/usr/bin/perl
#-----------------------------------------------------------------#
#define o numero de cartelas
$cartelas = "10000";
#define os numero q entram no sorteio, sendo eles de 1 ate 75
my @numeros_sorteio = ('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39','40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75');
#define quantos numeros uma cartela pode ter, sendo eles 25
$cartelas_limite = "25";
#quantas colunas terao por cartela.
$cartelas_colunas = "5";
#-----------------------------------------------------------------#
print "Content-Type: text/html\n\n";
@cartelas_salvas = "";
open(CARTELAS,">>teste.html");
for ($i=1; $i <= $cartelas; $i++){
print CARTELAS qq|<!-- $i -->\n<br><table border="1"><tr><td>|;
for ($x=1; $x <= $cartelas_limite; $x++) {
$numero = int rand @numeros_sorteio;
print CARTELAS "$numero";
if (($x * 5 == 25) or ($x * 5 == 50) or
($x * 5 == 75) or ($x * 5 == 100) or
($x * 5 == 125)) { print CARTELAS qq|</td></tr><tr><td>|; }
else { print CARTELAS qq|</td><td>|; }
}
print CARTELAS qq|</table> <br>\n\n|;
}
close(CARTELAS);

my problem is, i dont know how to dont make the numbers repeat if i will not use a data base to store numbers.
also i dont know how to order the numbers of that card into a <=> b
Quote Reply
Re: [NamedRisk] Bingo system In reply to
Hi,

I believe this;

Code:
my @numeros_sorteio = ('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39','40', '41', '42', '43', '44', '45', '46', '47', '48', ... '72', '73', '74', '75');

..could be written as;

Code:
my @numeros_sorteio = ( 1..75 );

Regarding the choice of random numbers, but not the same.. I would try something like;

Code:
@cartelas_salvas = "";
my $seen;
open(CARTELAS,">>teste.html");

for ($i=1; $i <= $cartelas; $i++){

print CARTELAS qq|<!-- $i -->\n<br><table border="1"><tr><td>|;
for ($x=1; $x <= $cartelas_limite; $x++) {
$numero = int rand @numeros_sorteio;
if ($seen->{$numero}) {
$x = $x-1;
next;
}

print CARTELAS "$numero ";
$seen->{$numero} = 1;
if (($x * 5 == 25) or ($x * 5 == 50) or ($x * 5 == 75) or ($x * 5 == 100) or ($x * 5 == 125)) {
print CARTELAS qq|</td></tr><tr><td>|;
} else {
print CARTELAS qq|</td><td>|;
}
}
print CARTELAS qq|</table> <br>\n\n|;
}
close(CARTELAS);

This is untested, but should work.

Hope that helps :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Bingo system In reply to
I think
Code:
if (($x * 5 == 25) or ($x * 5 == 50) or ($x * 5 == 75) or ($x * 5 == 100) or ($x * 5 == 125)) {
could be shortened down to:
Code:
if ($x * 5 % 25) {

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Bingo system In reply to
Yeah, I was a little confused as to what that was doing. Personally, I'd use something like;

if ($x % 5) {

..or similar.

Not 100% sure if that'll work in his case though <G>

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Bingo system In reply to
hi andy

i knew about 1..75 but i was typing 1 to 75 hand and i just oh what the hell let me use it...
but thx for the hit.


about the way u did there i didnt got the idea

$x=$x-1 ??

well anyway thx to try to help me.

i tryed to run it and just loads loads and loads .... and the way it was the results was like seconds.


about the x * 5 10 15 20

i knew that i can do x % 5
i was using it but dunno why it just stop working, so i was with headache thinking about the rand number always repeanting and just did a way to make it work.

its repeating like 6 times in a card :( like 44 2 times, 23 2 times, 2 2 times rrrr ....

me Pirate

[]īs
Quote Reply
Re: [NamedRisk] Bingo system In reply to
since i cant edit my reply...

i want to ask sry for you...

i have read later the code and i understood the way it works, its like stores in $seen and if repeat it will remove 1 from x making it run again and dont printing the number....

But it takes forever to finish Crazy

there is any fast solution ?

by the way great idea this way man thx =D
Quote Reply
Re: [NamedRisk] Bingo system In reply to
I'd stuff the random numbers into a hash till I had 25 keys. That will make sure you have no dupes:

Code:
#!/usr/bin/perl
use strict;
use warnings;

#-----------------------------------------------------------------#
#define o numero de cartelas
my $cartelas = 2; #10000;

#define os numero q entram no sorteio, sendo eles de 1 ate 75
my @numeros_sorteio = (1 .. 75);

#define quantos numeros uma cartela pode ter, sendo eles 25
my $cartelas_limite = 25;

#quantas colunas terao por cartela.
my $cartelas_colunas = 5;
#-----------------------------------------------------------------#

print "Content-Type: text/html\n\n";
#print "<pre>" . join("-", @numeros_sorteio) . "</pre>\n";

my %random = ();

for (my $x = 1; $x <= $cartelas; $x++) {
while (keys %random < $cartelas_limite) {
$random{sprintf('%.0f', rand((scalar @numeros_sorteio)) + .5)}++;
}

print qq~<h2>Card $x</h2>~;
print qq~<table border="1">\n~;
my $i = 0;
foreach my $n (keys %random) {
print qq~ <tr>\n~ unless $i % 5;
print qq~ <td>$n</td>\n~;
print qq~ </tr>\n~ unless ++$i % 5;
}
print qq~</table>\n~;

%random = ();
}

I ran it in a browser so I left out the file handles. I'm sure there is a faster, more direct way to do this; maybe one of the pros will chime in and enlighten us all :D

~Charlie
Quote Reply
Re: [Chaz] Bingo system In reply to
Here's another way. This pulls numbers from 15 number subsets of the 1..75 range like regular bingo cards so that they appear only in the correct column. They're also sorted as I think you stated you wanted (if not, just remove the line).

Code:
#!/perl/bin/perl
my $cards = 5;

print "Content-type: text/html\n\n";

for (my $card; $card < $cards; $card++) {
my $board = [];
for (my $col; $col < 5; $col++) {
my $start = $col == 0 ? 1 : $col * 15;
my $range = [$start .. $start + 15];
my $used = {};
for (my $i; $i < 5; $i++) {
my $num = $range->[int rand 15];
exists $used->{$num} and redo;
push @{$board->[$col]}, $num;
$used->{$num}++;
}
@{$board->[$col]} = sort { $a <=> $b } @{$board->[$col]};
}
print qq|<table border=1>|;
for (my $col; $col < 5; $col++) {
print qq|<tr>|;
for (my $row; $row < 5; $row++) {
print qq|<td>$board->[$row]->[$col]</td>|;
}
print qq|</tr>|;
}
print qq|</table><br>|;
}

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [Chaz] Bingo system In reply to
wow thx a lot guys

i m reading now and testing

thx andy chaz fuzzy

a learned a lot of new things here =D

also it was a good challange dont ?? =D

fuzzy i love the way u did it coz really go to a bingo side, the way to make the card, the built of the numbers.
also and the order thing =D

thx man u helped a lot.

chaz i like the way u use the hash to make it dont repeat thx man =D

both ways very fast.