# Back-Story

Every day I travel on the freeway.

When I am more bored than usual I sometimes like to play the following counting game I made up:

* As I join the freeway my count is ```0```
* Add ```1``` for every car that I overtake
* Subtract ```1``` for every car that overtakes me
* Stop counting when I reach my exit

What an easy game! What fun!

# Kata Task

You will be given
* The distance to my exit (km)
* How fast I am going (kph)
* Information about a lot of other cars 
 * Their time (relative to me) as I join the freeway. For example,
   * ```-1.5``` means they already passed my starting point ```1.5``` minutes ago
   * ```2.2``` means they will pass my starting point ```2.2``` minutes from now
 * How fast they are going (kph)

Find what is my "score" as I exit the freeway!

# Notes

* Assume all cars travel at a constant speeds

 Safety Warning 

If you plan to play this "game" remember that it is not really a game. You are in a **real** car.

There may be a temptation to try to beat your previous best score.

Please don't do that...

Difficulty: introductory

Starter code:

def freeway_game(dist_km_to_exit, my_speed_kph, other_cars):
	

Solutions:
def freeway_game(km, kph, cars):
    t = km / kph
    c = 0
    for dt, speed in cars:
        d = km - (t - dt/60) * speed
        if dt <= 0:
            c += d > 0
        else:
            c -= d < 0
    return c

def freeway_game(dist_km_to_exit, my_speed_kmph, other_cars):
    my_time_to_exit = dist_km_to_exit / my_speed_kmph
    return sum(
        + (lead < 0 and my_time_to_exit * speed < dist_km_to_exit + lead / 60 * speed)
        - (lead > 0 and my_time_to_exit * speed > dist_km_to_exit + lead / 60 * speed)
        for lead, speed in other_cars)

def freeway_game(dToExit, myS, cars):
    return sum( cS != myS and (0 < minutes/60 * cS/(cS-myS) < dToExit/myS) * (-1)**(cS > myS) for minutes,cS in cars )

def freeway_game(dist_km_to_exit, my_speed_kph, other_cars):
    score = 0
    for pair in other_cars:
        if(my_speed_kph == pair[1]):
            continue
        if( 0 < pair[1]*(pair[0]/60) / (pair[1] - my_speed_kph) < dist_km_to_exit/my_speed_kph):
            score = score - 1 if pair[0] > 0 else score + 1
    return score

def freeway_game(distance, speed, cars):
    score = 0
    exit = 60 * distance / speed
    for other_time, other_speed in cars:
        other_exit = 60 * distance / other_speed + other_time
        if other_time < 0 and other_exit > exit:
            score += 1
        elif other_time > 0 and other_exit < exit:
            score -= 1
    return score


def freeway_game(dist_km_to_exit, my_speed, other_cars):
    count = 0
    for (other_start_minute, other_speed) in other_cars:
        if other_speed == my_speed:
            continue
        other_start_time = other_start_minute / 60
        passing_point = (
            (other_start_time * my_speed * other_speed) /
            (other_speed - my_speed)
        )
        if 0 < passing_point < dist_km_to_exit:
            if my_speed > other_speed:
                count += 1
            else:
                count -= 1  
    return count

def freeway_game(dist_km_to_exit, my_speed_kph, other_cars):
    f_time = lambda s: dist_km_to_exit / s * 60
    duration = f_time(my_speed_kph)
    c = 0
    for p, s in other_cars:
        t = f_time(s) + p
        c += (t > duration and p < 0) - (t < duration and p > 0)
    return c

def freeway_game(d, speed, arr):
    t = d/speed*60
    print(t)
    c = 0
    
    for data in arr:
        if data[0] < 0:
            if d/data[1]*60 > t-data[0]:
                c += 1
        if data[0] > 0:
            if d/data[1]*60 < t-data[0]:
                c -= 1
    
    return c

def freeway_game(dist_km_to_exit, my_speed_kph, other_cars):
    t0 = dist_km_to_exit / my_speed_kph
    time_car = lambda dist0, time_delta, speed: (dist0 + time_delta*speed/60) / speed
    result = 0
    for car in other_cars:
        if car[0] > 0 and time_car(dist_km_to_exit, car[0], car[1]) < t0:
            result -= 1
            continue
        if car[0] < 0 and time_car(dist_km_to_exit, car[0], car[1]) > t0:
            result += 1
    return result

def freeway_game(dist, speed, cars):
    res, exit = 0, dist / speed
    check = lambda t, s1, s2: s * t < exit * s2 * 60
    
    for t,s in cars:
        if t < 0 and speed > s:
            res += check(-t, s, speed-s)
        elif t > 0 and speed < s:
            res -= check(t, s, s-speed)
    return res