You throw a ball vertically upwards with an initial speed `v (in km per hour)`. The height `h` of the ball at each time `t`
is given by `h = v*t - 0.5*g*t*t` where `g` is Earth's gravity `(g ~ 9.81 m/s**2)`. A device is recording at every **tenth
of second** the height of the ball.
For example with `v = 15 km/h` the device gets something of the following form:
`(0, 0.0), (1, 0.367...), (2, 0.637...), (3, 0.808...), (4, 0.881..) ...`
where the first number is the time in tenth of second and the second number the height in meter.
# Task
Write a function `max_ball` with parameter `v (in km per hour)` that returns the `time in tenth of second`
of the maximum height recorded by the device.
# Examples:
`max_ball(15) should return 4`

`max_ball(25) should return 7`
# Notes
- Remember to convert the velocity from km/h to m/s or from m/s in km/h when necessary.
- The maximum height recorded by the device is not necessarily the maximum height reached by the ball.

Difficulty: introductory

Starter code:

def max_ball(v0):
	

Solutions:
"""
h = vt-0.5gt^2
let h = 0 [that is, when the ball has returned to the ground]
=> 0 = vt-0.5gt^2
=> 0.5gt^2 = vt
=> 0.5gt = v
=> t = 2v/g - the total time the ball is in the air.
=> t at max height  = v/g
"""

def max_ball(v0):
    return round(10*v0/9.81/3.6)

def max_ball(v0):
    return round(10*v0/9.81/3.6)

def max_ball(v):
    return round(v / 3.5316)
    
    


def max_ball(v0, g=9.81):
    v = v0 / 3.6
    prev = 0
    for i in range(1000):
        t = i * 0.1
        h = v*t - 0.5*g*t*t
        if h < prev:
            return i - 1
        prev = h

def max_ball(v0):
    return round( v0/3.6/9.81*10 )

def max_ball(v0):
    # acceleration
    g = 9.81 
    # height from ground, u is time in s, v speed in m/s
    def h(u):
        return v*u - 0.5*g*u*u
    # from km/h to m/s
    v = v0 * 1000 / 3600.0
    # in t = v/g the derivative is 0, the height is max
    t = v / g
    # record done every 0.1 s; tm is in tenth of second
    tm = int(t*10)
    # device max is before (<=) or after tm (>)
    h1 = h( tm/10.0 )
    h2 = h( (tm+1)/10.0 )
    mx = max( h1, h2 )
    # is the recorded max before or after the theoric max
    if (mx == h( tm/10.0 )):
        return tm
    else:
        return tm+1

max_ball=lambda v0:round(v0*1000/360/9.81)

def max_ball(v0):
    v = v0 * (1000/3600)
    g = 9.81
    t = 0
    record = []
    while v * t - 0.5 * g * t * t >= 0:
        h = v * t - 0.5 * g * t * t
        record.append(h)
        t += 0.1
    return (record.index(max(record)))

from itertools import count
def max_ball(v0):
    g = 9.81
    c = count(0, 0.1)
    hh = -0.1
    while True:
        t = next(c)
        h = v0*1000/3600*t - 0.5*g*t*t
        if h-hh>0:
            hh = h
        else:
            return int(round(t*10, 2))-1


def max_ball(v0):
    return round(10 * (v0 / 3.6) / 9.81)