Every year, Ciena India celebrates Diwali in a grand way. We have various events organized for a complete week which ends with an amazing Friday night party. Apart from the events/competitions for the enthusiasts like Plays, Pictionary, Antakshari,etc. , we have a few for lazy bunch like me who don’t mind participating if we can do it from our desks like e-quiz , e-tambola, etc.
E-Tambola, is version of Tambola where each participant (all >600 employees in our case) take their tickets to respective seats and the caller sends two sets of random numbers each day in email. The person who completes any of the Rows or the full house needs to immediately send an email to the caller. Prize is given on first come first serve basis.
Although it is a simple process and doesn’t take much time to mark off numbers on tickets, I wrote a small PHP script to check whether I have completed any of the winning combinations and send email to caller if I won.
Before I start to explain how I did it, the why seems necessary as many of my colleagues couldn’t understand the reason behind it. Here are a few reasons:-
- Every time the email came, it was a pain to find that damn ticket quickly in my desk drawers full with other *very important* documents.
- It was not just the ticket that I had to find, I also needed a pen/marker which somehow magically goes missing exactly when I need it
- Even after getting the winning combination, you’d be a winner only when you were the first one to send confirmation email to the caller and I thought I could automate the complete process to make sure I was the first to send confirmation email.
- I could come up with other random reasons but the main reason I had to do this is precisely depicted in this comic strip by commitstrip.com “For the love of code!”
This was fairly easy as there were no complex winning combinations. I had to hard-code the ticket numbers and find the intersection of each row with numbers from the email. If the input numbers matched any of the winning combination (First five, any of the rows or full house) then show the hyperlink to send appropriate email. Here’s the PHP code:-
Note:- This was a quick n dirty solution and it is possible to do it in a better way using PHP or other languages. I am not a web developer, I have used PHP previously for very simple purposes like writing crawler for weworkremotely app, to send emails via internetusage landing page, creating my Infosys last day “mail” webpage (more on this some other time), etc..
There is a separate php file for input array, so that if I need to track more than one ticket (for my colleagues) then I need to edit only one file for input. It looked like this:-
$input_array = array(24,19,20,73,68,67,72,13,5,26,38,87,88,35,80,31,90,77,69,81);
I thought providing input will be an easy task, the caller will send us a comma separated list of numbers in email and I would just copy paste it in the input file, but these over enthusiastic people have to beautify everything! They sent the numbers in an image, something like this-
Sadly, now I have to type each number in input array and it takes the same time it’d take people to do it manually, but as I said, it’s all for the love of code! 😀