Introduction
You are the manager of the electronics department in a major retail store and the biggest sales day of the year is this Friday. To help manage the crowds, your store is implementing a ticket system for the biggest deals, where customers must present a ticket before purchasing an item. Your job is to write a program to validate the tickets.
Since the only available computer in the store (due to budget cuts) is a dinosaur with a broken keyboard, (and all you have is USB keyboards, which aren't compatible) you'll have to input your program with a mouse. Therefore, your program should be as short as possible.
Products
You store is running sales on the five different products listed below. Each product has an all lowercase name and different rules on how many can be purchased and at what time of day.
television: There are5flat-screen televisions in stock that may be purchased from00:00:00(midnight) to00:59:59.smartphone: There are10smartphones in stock, but any customer in line from00:00:00(midnight) to00:59:59receives a voucher for one once they run out.tablet: There are10tablets that may be purchased at anytime.laptop: There are an unlimited number of laptops that may be purchased from00:00:00(midnight) to07:59:59.lightbulb: There are an unlimited number of light bulbs that may be purchased at anytime.
Input
A multi-line string with each line in the following format. Lines are sorted by the time-stamp.
<time stamp> <product name> <ticket number> - The ticket number is 8 digits long. The last digit is a check-digit equal to the sum of the first seven digits modulo 10. To be valid, a ticket number must have the correct check-digit and must be strictly greater than all previous ticket numbers.
- The product name is one of the string listed above.
- The time stamp is the time of day in the format
HH:MM:SSwhereHHis the two-digit hour from 00-23, andMMandSSare the two-digit minute and second respectively.
Output
The output is one of the following strings, with one line per ticket. The conditions must be applied in order.
Expired offer(Applies to televisions, smartphones, and laptops.) The time-stamp of the ticket is after the cutoff to buy the product.Invalid ticketEither the ticket number is less than or equal to the number of the previous ticket, or the check-digit is invalid.Give voucher(Applies to smartphones.) The product is out of stock, but all the customers in line before the offer expires get a rain check.Out of stock(Applies to televisions and tablets.) All of the product has been sold. Sorry, quantity was limited.AcceptedAll conditions are met, so give them the product. Note that only accepted tickets reduce the number of items in stock.
Example
Input Output ---------------------------- -------------- 00:00:00 television 00010001 Accepted 00:00:25 smartphone 00011697 Accepted 00:01:25 laptop 00030238 Accepted 00:02:11 smartphone 00037291 Accepted 00:02:37 lightbulb 00073469 Invalid ticket 00:03:54 smartphone 00096319 Accepted 00:05:26 tablet 00152514 Accepted 00:06:21 tablet 00169893 Accepted 00:07:10 television 00190268 Accepted 00:07:47 smartphone 00194486 Accepted 00:07:55 tablet 00220071 Accepted 00:08:20 lightbulb 00321332 Accepted 00:10:01 smartphone 00409867 Accepted 00:11:10 tablet 00394210 Invalid ticket 00:11:46 television 00581060 Accepted 00:12:44 lightbulb 00606327 Accepted 00:13:16 tablet 00709253 Accepted 00:13:53 television 00801874 Accepted 00:14:47 laptop 00832058 Accepted 00:15:34 smartphone 00963682 Accepted 00:16:24 smartphone 01050275 Accepted 00:17:45 tablet 01117167 Accepted 00:18:05 laptop 01107548 Invalid ticket 00:19:00 lightbulb 01107605 Invalid ticket 00:19:47 lightbulb 01492983 Accepted 00:19:50 smartphone 01561609 Accepted 00:21:09 television 01567098 Accepted 00:21:42 laptop 01597046 Accepted 00:22:17 smartphone 01666313 Accepted 00:24:12 tablet 01924859 Accepted 00:24:12 smartphone 02151571 Accepted 00:25:38 smartphone 02428286 Give voucher 00:31:58 television 02435284 Out of stock 00:35:25 television 02435295 Out of stock 00:52:43 laptop 02657911 Invalid ticket 00:53:55 smartphone 02695990 Give voucher 01:08:19 tablet 02767103 Accepted 01:34:03 television 02834850 Expired offer 01:56:46 laptop 02896263 Accepted 02:02:41 smartphone 03028788 Expired offer 02:30:59 television 03142550 Expired offer 02:51:23 tablet 03428805 Accepted 03:14:57 smartphone 03602315 Expired offer 03:27:12 television 03739585 Expired offer 03:56:52 smartphone 03997615 Expired offer 04:07:52 tablet 04149301 Accepted 04:12:05 lightbulb 04300460 Invalid ticket 04:24:21 laptop 04389172 Accepted 04:40:23 lightbulb 04814175 Accepted 04:40:55 tablet 04817853 Accepted 04:42:18 smartphone 04927332 Expired offer 05:06:43 tablet 05079393 Out of stock 05:16:48 tablet 05513150 Out of stock 05:33:02 television 05760312 Expired offer 05:43:32 tablet 06037905 Out of stock 06:12:48 smartphone 06440172 Expired offer 06:35:25 laptop 06507277 Accepted 06:42:29 lightbulb 06586255 Invalid ticket 06:55:31 lightbulb 06905583 Accepted 06:55:33 lightbulb 06905583 Invalid ticket 07:40:05 smartphone 07428006 Expired offer 07:49:12 television 07588086 Expired offer 08:14:56 laptop 08111865 Expired offer I have tried to make the example cover every possible output scenario, but please leave a comment if anything is unclear.
This is code-golf, you may write a program or function, and standard loop-holes are disallowed.