You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

count_analysis.py 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import million.analyze.message_evaluation as msg_val
  2. def check_extra_or_missing_letter(word, reference):
  3. len_word = len(word)
  4. len_ref = len(reference)
  5. if abs(len_word - len_ref) != 1:
  6. return False
  7. shortest = word if len_word < len_ref else reference
  8. longest = word if len_word > len_ref else reference
  9. for i in range(len(shortest)):
  10. if shortest[i] != longest[i]:
  11. return shortest[i:] == longest[i + 1 :]
  12. return True
  13. def check_single_letter_differ(word, reference):
  14. return sum(1 for x, y in zip(reference, word) if x != y) == 1
  15. def check_letter_swap(word, reference):
  16. if len(word) != len(reference):
  17. return False
  18. for i in range(len(word) - 1):
  19. if word[i] != reference[i]:
  20. return word[i + 1] + word[i] + word[i + 2 :] == reference[i:]
  21. return False
  22. def check_typo(word, reference):
  23. if len(reference) == len(word):
  24. return check_single_letter_differ(word, reference) or \
  25. check_letter_swap(word, reference)
  26. else:
  27. return check_extra_or_missing_letter(word, reference)
  28. def find_value_around_index(messages, value, idx, amplitude) -> int:
  29. check_value = lambda x: msg_val.get(messages[x]) == value
  30. if check_value(idx):
  31. return idx
  32. for offset in range(1, amplitude):
  33. o_idx = idx + offset * +1
  34. if check_value(o_idx):
  35. return o_idx
  36. o_idx = idx + offset * -1
  37. if check_value(o_idx):
  38. return o_idx
  39. return -1