Guest User

10. Winning Ticket

a guest
Jul 20th, 2020
109
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def cut_in_half(word: str):
  2. word_half = len(word) // 2
  3. first_half = word[:word_half]
  4. second_half = word[word_half:]
  5.  
  6. first_half_count = {}
  7. second_half_count = {}
  8.  
  9. for j in first_half:
  10. if j not in first_half_count.keys():
  11. first_half_count[j] = 0
  12.  
  13. first_half_count[j] += 1
  14.  
  15. for j in second_half:
  16. if j not in second_half_count.keys():
  17. second_half_count[j] = 0
  18.  
  19. second_half_count[j] += 1
  20.  
  21. is_jackpot = False
  22. symbol = ''
  23. match_len = 0
  24.  
  25. for k, v in first_half_count.items():
  26. if k in "@#$^":
  27. for x, y in second_half_count.items():
  28. if k == x:
  29. if 5 < v < 11:
  30. if y == 10:
  31. is_jackpot = True
  32. symbol = k
  33. match_len = min(v, y)
  34.  
  35. if is_jackpot:
  36. return [symbol, match_len, "jackpot"]
  37. elif 6 <= match_len <= 9:
  38. return [symbol, match_len]
  39. else:
  40. return None
  41.  
  42.  
  43. tickets = input().split(", ")
  44.  
  45. for ticket in tickets:
  46. ticket = ticket.rstrip().lstrip()
  47. if len(ticket) == 20:
  48. match = False
  49.  
  50. for i in ticket:
  51. if i in "@#$^":
  52. match = True
  53. break
  54.  
  55. if not match:
  56. print(f'ticket "{ticket}" - no match')
  57.  
  58. else:
  59. res = cut_in_half(ticket)
  60.  
  61. if res is not None:
  62. length = res[1]
  63. match_symbol = res[0]
  64. if len(res) == 3:
  65. print(f'ticket "{ticket}" - {length}{match_symbol} Jackpot!')
  66. elif len(res) == 2:
  67. print(f'ticket "{ticket}" - {length}{match_symbol}')
  68. else:
  69. print(f'ticket "{ticket}" - no match')
  70. else:
  71. print("invalid ticket")
RAW Paste Data