Guest User

Untitled

a guest
Jun 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. def count_cross(rph_a, rph_b, hours=1, pos_a=0, pos_b=0, opposite_dir=True):
  2. import math
  3.  
  4. cross_count = 0
  5. max_rounds = hours * max(rph_a, rph_b)
  6. for i in range(int(math.ceil(max_rounds))):
  7. round_fr = (max_rounds - i) if i == int(math.floor(max_rounds)) else 1
  8. a_ahead = pos_a > pos_b if not pos_a == pos_b else "eq"
  9. pos_a += (float(rph_a) / max(rph_a, rph_b)) * round_fr
  10. pos_b += (float(rph_b) / max(rph_a, rph_b)) * round_fr
  11.  
  12. if opposite_dir:
  13. pos_b = 1 - pos_b
  14.  
  15. if opposite_dir:
  16. cross_count += 2 if pos_a % 1 == pos_b % 1 else 1
  17. else:
  18. if (
  19. a_ahead != "eq"
  20. and (a_ahead and pos_b >= pos_a)
  21. or (not a_ahead and pos_b >= pos_a)
  22. ):
  23. cross_count += 1
  24.  
  25. pos_a %= 1
  26. pos_b %= 1
  27.  
  28. return cross_count
Add Comment
Please, Sign In to add comment