Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting the Occurances of a Number in a String

Status
Not open for further replies.

gm199

Programmer
Aug 9, 2001
37
US
Basically what I need is to check the Lotto numbers against a database to see how many numbers I hit (how many are equal).

I need some help on how to compare the values from the week's numbers and the ones I used to bet and show on the screen how many and what numbers.

Ie.
Lotto #s 3, 7, 18, 23, 45, 47
My #s 1, 7, 14, 26, 45, 47


Matchs: 3 numbers -> 7, 45 and 47


Thanks for any clue
 
Exactly how are the number strings formatted? If they are separated by a comma, you could use the following:
[pre]my(@my_numbers, @lotto_numbers, @matches);
@my_numbers = (1, 7, 14, 26, 45, 47); # assign your numbers
@lotto_numbers = (3, 7, 18, 23, 45, 47); # assign the lotto numbers
print ("Matches: ");
foreach my $number (@lotto_numbers)
{
foreach my $my_number (@my_numbers)
{
if ($my_number == $number)
{
print ("$my_number "); # if it's a match, print the value
}
}
}[/pre]

//Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top