Guest User

Untitled

a guest
Oct 22nd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. input_string_1 = """3 15 4
  2. 4 2 3 3 9
  3. F L Y W B E G A L K R U B E T
  4. L H G E C K Y U B H L U G A F
  5. K Y F M P U B K F I G O N S Y"""
  6.  
  7. input_string_2 = """4 13 6
  8. 7 4 1 4 3 5 1 4
  9. P I M L H A K E D P I L A
  10. M E H D E L P R I C A T H
  11. L I G R H P E D L E T I P
  12. H A D G H L O I D O N P D"""
  13.  
  14. input_string = {}
  15. input_string[1] = input_string_1
  16. input_string[2] = input_string_2
  17.  
  18. def get_noise_threshold(input_string):
  19. return int(input_string.split("\n")[0][-1])
  20.  
  21. def get_letters(input_string):
  22. letters = input_string.split("\n")[2:]
  23. letters = " ".join(letters).split(" ")
  24. return letters
  25.  
  26. def get_word_lengths(input_string):
  27. line_2 = input_string.split("\n")[1]
  28. word_lengths = [int(wl) for wl in line_2.split(" ")]
  29. return word_lengths[1:]
  30.  
  31. def get_counter(letters):
  32. counter = {}
  33. for a in set(letters):
  34. counter[a] = 0
  35. for a in letters:
  36. counter[a] += 1
  37. return counter
  38.  
  39. def get_message(letters, counter_letters, noise_threshold):
  40. return [a for a in letters if counter_letters[a] != noise_threshold]
  41.  
  42. def print_message(msg, word_lengths):
  43. output_string = []
  44. start = 0
  45. for length in word_lengths:
  46. output_string.append("".join(msg[start:start + length]))
  47. start = start + length
  48. print(" ".join(output_string))
  49.  
  50. def main():
  51. testcase = input_string[1]
  52. noise_threshold = get_noise_threshold(testcase)
  53. letters = get_letters(testcase)
  54. word_lengths = get_word_lengths(testcase)
  55. counter_letters = get_counter(letters)
  56. msg = get_message(letters, counter_letters, noise_threshold)
  57. print_message(msg, word_lengths)
  58.  
  59. if __name__ == "__main__":
  60. main()
Add Comment
Please, Sign In to add comment