Lottery result checker

So, i made a simple lottery number generator like this:

for i in `seq 10`; do seq 1 35 | shuf -n 7 | sort -g | tr '\n' ' ' ;echo; done

i've file with winning numbers:

Eg:

1 10 15 20 25 30 35
2 6 10 14 18 22 26

My problem here is how to compare or check if my generated numbers are match or i won something. To get some cash i need at least four numbers to match out of seven.

Do you have any idea how to create script for this?

Thank you in advance!

for i in `seq 10`; do seq 1 35 | shuf -n 7 | sort -g | tr '\n' ' ' ;echo; done > winning_numbers

for i in `seq 1`; do seq 1 35 | shuf -n 7 | sort -g | tr '\n' ' ' ;echo; done > my_numbers

awk '
BEGIN {printf("%-25s\t%-25s\t%-10s\t%-10s\n", "Winning Numbers", "My Numbers", "#s Matched", "Result")}
NR==FNR {for (i=1; i<=NF; i++) {w[NR]=$0; wn[NR,i]=$i}; r=NR; next;}
{
   for (i=1; i<=r; i++) {
      c=0;
      for (j=1; j<=NF; j++) for (k=1; k<=NF; k++) if ($j==wn[i,k]) c++;
      printf("%-25s\t%-25s\t%-10d\t%-10s\n", w, $0, c, ((c < 4) ? "lose" : "win"));
   }
}
' winning_numbers my_numbers
1 Like

Thanks rdrtx1! This is pretty amazing!

If i get the point this script checks the placement of the number, right?

So if i have only one number on the right place it says 'lose' with one match.

Like here:

Winning Numbers          	My Numbers               	#s Matched	Result    
8 11 12 19 31 34 35      	6 7 8 10 16 27 30        	0         	lose      
8 11 12 19 31 34 35      	7 8 11 12 19 31 35       	1         	lose 

But basically i've matched 6

See revised. All positions are checked. If match by position then use previous.

1 Like

Thanks! I'll use this new one.

By the way, if you do happen to match 6 numbers, I think rdrtx1 should be given a small cut.

2 Likes

Hi Rdrtx1,

Assume if I have the shuffled numbers from 1 to 35 and I don't want to check all the number from 1-35, whereas, I need to check the number randomly on my own.
How can this be achieved.

Slightly different approach borrowing from rdrtx1:

awk '
NR == 1   {printf("%-25s\t%-25s\t%-10s\t%-10s\n", "Winning Numbers", "My Numbers", "#s Matched", "Result")
           for (n=split ($0, TMP); n>0; n--) MYNO[TMP[n]]
           MN = $0
           split ("win lose", RES)
           next
          }

    {for (i=1; i<=NF; i++)    c += ($i in MYNO)
     printf "%-25s\t%-25s\t%-10d\t%-10s\n", $0, MN, c, RES[1+(c < 4)]
     c = 0
    }
' my_numbers winning_numbers

For your new request, I'm not quite sure I understand it. How about rephrasing it? Not the original requestor.

The script shown in post #2 on this thread only checks for numbers as defined by PuLPi's posted lottery number generator (7 randomly picked numbers, not all 35). The script also generates the "my_numbers" file the same way (7 randomly picked numbers but can be more or less numbers). The input of the "my_numbers" can be change as needed. If the numbers are to be input manually then a prompt can be used to read the numbers (on a loop if entered one by one) or the numbers can be read from an existing file.

hi ,

Let me put it in a different way with words.

1) Assume the lottery have numbers from 1-50.
2) Out of this 50 numbers, I am going to pick up only 35 numbers randomly.
3) so, my total numbers would be 35 numbers shuffled from [1-50] nos.
[eg: 1,4,6,7,11,30,32,40,46,49]

4) I have list of winning numbers in [my_number.txt] file.
5) Now, the script should check within my 35 numbers comparing the file [my_number.txt] and should give the results .. The result number should be 6 nos.
[eg: 1 6 30 32 46 49 ]

Thanks in Advance.

-Siva

Moderator comments were removed during original forum migration.