Re: OT: script to check Lotto numbers

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

 



On 11Oct2020 22:08, None <olivares33561@xxxxxxxxxxxxxx> wrote:
>On Sunday, October 11, 2020 3:54 PM, Cameron Simpson <cs@xxxxxxxxxx> wrote:
>> 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.
[... shell script based suggestions ...]
>
>Thank you for your help.  This is not a homework problem.

Fair enough.

>It is a time saving thing, we can check online input the numbers one by one, but there are 15 sets.  It takes time.  Having a bash script can do the job, but question is do we get the winning numbers as integers, or do we compare them as strings?

1: You don't need bash. Write for the Bourne shell - almost none of
bash's extensions are of much value for programming, and _every_ system
has a Bourne shell (/bin/sh) - "bash" is just a dialect.

2: The shell is good at strings (for basic stuff, which this is). Work
in strings. Your text file is strings. You're only testing for equality
- you don't need arithmetic, strings are fine. Think of the numbers as
  symbols instead of numeric values.

>If we compare numbers (num1 == $num1)
>Or [ ] I have problems with the scripts working correctly and getting '(' expected.

The case statement lets you sidestep that kind of syntactic thing. Hence the
examples.

>I will try to write the script and ask for help if I run into problems.

Sounds good to me.

>I have seen pages where there are references with awk, seq and other commands
>https://www.unix.com/shell-programming-and-scripting/276553-lottery-number-checker.html
>https://www.txlottery.org/export/sites/lottery/Games/Check_Your_Numbers.html
>
>I wanted to use grep command by piping the cat command, but I have dilemma that if an array is used, the code is cleaner and more efficient.

Gah. Use strings!

All these solutions seem overly complex to me. My personal mantra is:
use the smallest tool which succintly expresses the solution.

In this case, you can do it _all_ in the shell without reaching for more
general tools.

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