Guest User

Winning Ticket

a guest
Aug 6th, 2020
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. tickets = input().split(', ')
  2. valid = '@#$^'
  3.  
  4.  
  5. def max_repeating(string, symbol):    
  6.     if symbol not in string:
  7.         return 0
  8.  
  9.     max_count = 0
  10.     curr_count = 0
  11.  
  12.     for i in range(len(string)):
  13.         if string[i] == symbol:
  14.             curr_count += 1
  15.         else:
  16.             if max_count < curr_count:
  17.                 max_count = curr_count
  18.             curr_count = 0
  19.  
  20.     return max(max_count, curr_count)
  21.  
  22.  
  23. for t in tickets:
  24.     t = t.strip()
  25.     if len(t) != 20:
  26.         print(f'invalid ticket')
  27.         continue
  28.  
  29.     match = False
  30.     Jack = False
  31.  
  32.     middle = len(t) // 2
  33.     first = t[:middle]
  34.     second = t[middle:]
  35.  
  36.     for v in valid:
  37.         if t.count(v) == 20:
  38.             Jack = True
  39.             print(f'ticket "{t}" - {10}{v} Jackpot!')
  40.             break
  41.  
  42.         f = max_repeating(first, v)
  43.         s = max_repeating(second, v)
  44.  
  45.         if 6 <= f <= 10 and 6 <= s <= 10:
  46.             match = True
  47.             print(f'ticket "{t}" - {min(f, s)}{v}')
  48.             break
  49.  
  50.     if not match and not Jack:
  51.         print(f'ticket "{t}" - no match')
  52.  
  53.  
Advertisement
Add Comment
Please, Sign In to add comment