Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def count_cross(rph_a, rph_b, hours=1, pos_a=0, pos_b=0, opposite_dir=True):
- import math
- cross_count = 0
- max_rounds = hours * max(rph_a, rph_b)
- for i in range(int(math.ceil(max_rounds))):
- round_fr = (max_rounds - i) if i == int(math.floor(max_rounds)) else 1
- a_ahead = pos_a > pos_b if not pos_a == pos_b else "eq"
- pos_a += (float(rph_a) / max(rph_a, rph_b)) * round_fr
- pos_b += (float(rph_b) / max(rph_a, rph_b)) * round_fr
- if opposite_dir:
- pos_b = 1 - pos_b
- if opposite_dir:
- cross_count += 2 if pos_a % 1 == pos_b % 1 else 1
- else:
- if (
- a_ahead != "eq"
- and (a_ahead and pos_b >= pos_a)
- or (not a_ahead and pos_b >= pos_a)
- ):
- cross_count += 1
- pos_a %= 1
- pos_b %= 1
- return cross_count
Add Comment
Please, Sign In to add comment