Tambola tickets generator (#169)

* Adds utility to generate Tambola tickets

* Adds utility to generate Tambola tickets
This commit is contained in:
Synster 2020-10-05 14:09:41 +05:30 committed by GitHub
parent 881f70e6e8
commit fa07478deb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 99 additions and 0 deletions

View File

@ -150,8 +150,10 @@ So far, the following projects have been integrated to this repo:
|[YTS Torrents](yts_torrents)|[Mayank Nader](https://github.com/makkoncept)|
|[COVID visualiser (real-time) ](covdi_visualiser)|[Tushar Gupta](https://github.com/tushar5526)|
|[Random_Email_Generator](Random_Email_Generator)|[Shubham Garg](https://github.com/shub-garg)|
|[Tambola_Ticket_Generator](Tambola_Ticket_Generator)|[Amandeep_Singh](https://github.com/Synster)|
| [Py_Cleaner](Py_Cleaner) | [Abhishek Dobliyal](https://github.com/Abhishek-Dobliyal)
## How to use :
- Clone/Download the directory and navigate to each folder. Or...

View File

@ -0,0 +1,44 @@
# Tambola ticket generator
This is a simple utility to generate tambola tickets
## Requirement
* Python 3
* numpy
* tabulate
```bash
pip install -r requirements.txt
```
## Usage
```bash
$ python main.py
╒═══╤════╤════╤════╤════╤════╤════╤════╤════╕
│ 0 │ 14 │ 0 │ 32 │ 0 │ 0 │ 61 │ 71 │ 81 │
├───┼────┼────┼────┼────┼────┼────┼────┼────┤
│ 4 │ 0 │ 24 │ 33 │ 45 │ 0 │ 63 │ 0 │ 0 │
├───┼────┼────┼────┼────┼────┼────┼────┼────┤
│ 0 │ 0 │ 25 │ 37 │ 49 │ 59 │ 0 │ 79 │ 0 │
╘═══╧════╧════╧════╧════╧════╧════╧════╧════╛
```
```bash
$ python main.py --count 2
╒═══╤════╤════╤════╤════╤════╤════╤════╤════╕
│ 0 │ 14 │ 0 │ 32 │ 0 │ 0 │ 61 │ 71 │ 81 │
├───┼────┼────┼────┼────┼────┼────┼────┼────┤
│ 4 │ 0 │ 24 │ 33 │ 45 │ 0 │ 63 │ 0 │ 0 │
├───┼────┼────┼────┼────┼────┼────┼────┼────┤
│ 0 │ 0 │ 25 │ 37 │ 49 │ 59 │ 0 │ 79 │ 0 │
╘═══╧════╧════╧════╧════╧════╧════╧════╧════╛
╒═══╤════╤════╤════╤════╤════╤════╤════╤════╕
│ 1 │ 0 │ 0 │ 32 │ 42 │ 0 │ 61 │ 72 │ 0 │
├───┼────┼────┼────┼────┼────┼────┼────┼────┤
│ 0 │ 17 │ 24 │ 0 │ 45 │ 0 │ 0 │ 77 │ 82 │
├───┼────┼────┼────┼────┼────┼────┼────┼────┤
│ 5 │ 0 │ 26 │ 39 │ 49 │ 59 │ 0 │ 0 │ 0 │
╘═══╧════╧════╧════╧════╧════╧════╧════╧════╛
```

View File

@ -0,0 +1,51 @@
"""
Tambola Ticket generator
ask (c) 2020. All rights reserved.
"""
import argparse
import numpy as np
from tabulate import tabulate
def shuffle_array(a):
while (~a.any(axis=1)).any():
[np.random.shuffle(a[:, i]) for i in range(3)]
return a
def generate_ticket():
ticket = np.full(27, 1).reshape(9, 3)
ticket[:4, :] *= 0
ticket = shuffle_array(ticket)
for i in range(9):
num = np.arange(1, 10) if i < 8 else np.arange(1, 11)
np.random.shuffle(num)
num = np.sort(num[:3])
ticket[i, :] *= (num + i * 10)
return ticket.T
def get_tickets(args):
tickets = []
for _ in range(args.count):
tickets.append(generate_ticket())
return tickets
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--count', help="Generates and returns tambola tickets given by count", type=int,
default=1)
args = parser.parse_args()
return get_tickets(args)
if __name__ == "__main__":
generated_tickets = main()
print("Generated {0} tickets".format(len(generated_tickets)))
for t in generated_tickets:
print(tabulate(t, tablefmt='fancy_grid'))

View File

@ -0,0 +1,2 @@
numpy==1.19.2
tabulate==0.8.7