Re: OT: script to check Lotto numbers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11Oct2020 18:54, None <olivares33561@xxxxxxxxxxxxxx> wrote:
>The play 15 different sets of numbers and to check if they won any prize a script using a chain of if statements or case statements would be correct to implement this.  AWK may also do the job?
>There are six numbers that we need to check let us suppose that we had the numbers in a file numbers.dat and it has the fifteen combinations
>
>2 - 3 - 5 - 7 - 11 - 13
>...
>...
>15 versions
>
>Check against the winning numbers
>
>2 - 7 - 23 - 38 - 51 - 53
>
>Faster way to check compare string? Compare numbers one by one and check for at least 3

This feels somewhat like homework, so I'll provide suggests instead of 
complete code. Besides, you probably want to write it yourself.

_If_ you're doing this in the shell (/bin/sh), a case statement is a 
surprisingly quick way to test the presence of a value against a list.

Suppose you've got one number in $value. Suppose you have the list to 
compare against in $numbers as a string separated by commas. Then this:

    case ",$numbers," in
        *",$value,"*)
          echo "$value is present in $numbers!"
          ;;
    esac

can be used to check. Since you're counting matches set a counter to 0 
and iterate over the values, and increment the counter once in the case 
statement. Check the counter after the loop.

If you've really got a string like "2 - 3 - 5 - 7 - 11 - 13" it is 
trivial to use " - " as the separator instead of a comma.

You can easily write a shell function to compare a batch of values.

Then you can iterate over the file in numbers.dat looking counting the 
matches for each line:

    while read numbers
    do
        ... compare $numbers against your picked numbers ...
    done < numbers.dat

This if-statement:

>If (successful numbers >= 3)
>  Write you have won $3
>If (successful numbers >= 4)
>  Write you have won $56
>If (successful numbers >= 5)
> Write you have won $156
>If (successful numbers > 5)
>  Write you are a millionaire and have won the jackpot

Is better written as a case statement, testing the count from your
comparison function.

    case $count in
      ......... the various values ...
      5) echo "156" ;;
      6) echo "you are a millionaire" ;;
    esac

Cheers,
Cameron Simpson <cs@xxxxxxxxxx>
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@xxxxxxxxxxxxxxxxxxxxxxx



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux