bl00dt3ars

10. Winning Ticket

Aug 12th, 2021 (edited)
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. import re
  2.  
  3. pattern = r'[$]{6,10}|[#]{6,10}|[@]{6,10}|[\^]{6,10}'
  4. tickets = [el.replace(' ', '') for el in input().split(',')]
  5.  
  6. for ticket in tickets:
  7.     if not len(ticket) == 20:
  8.         print('invalid ticket')
  9.     else:
  10.         left_half = ticket[:10]
  11.         right_half = ticket[10:]
  12.         left_match = ''.join(re.findall(pattern, left_half))
  13.         right_match = ''.join(re.findall(pattern, right_half))
  14.         num_of_symbols = min(len(left_match), len(right_match))
  15.         if num_of_symbols == 0 or not left_match[:num_of_symbols] == right_match[:num_of_symbols]:
  16.             print(f'ticket "{ticket}" - no match')
  17.         else:
  18.             winning_symbol = left_match[0]
  19.             text_to_print = f'ticket "{ticket}" - {num_of_symbols}{winning_symbol}'
  20.             if num_of_symbols == 10:
  21.                 text_to_print += ' Jackpot!'
  22.             print(text_to_print)
Add Comment
Please, Sign In to add comment