def solution2(a, b, n=100000, max_y=None, min_y=0): max_y = max([f(random.uniform(a, b)) for i in xrange(10 * n)]) if not None else max_y print max_y coordinates = [(random.uniform(a, b), random.uniform(min_y, max_y)) for i in xrange(n)] # file2_b = open('test2_b.txt', 'r+') k = 0 for x, y in coordinates: # print >> file2_b, (x, y) if f(x) >= y: k += 1 # file2_b.close() return (max_y - min_y) * (b - a) * (float(k) / n)
# Python3 from solution1 import startupName as f qa = [(['coolcompany', 'nicecompany', 'legendarycompany'], ['e', 'l']), (['nameone', 'nametwo', 'namethree'], ['o', 't']), (['heh', 'hah', 'funny'], ['h']), (['amazon', 'ebay', 'aliexpress'], ['e']), (['abc', 'def', 'hijk'], []), (['cool', 'looc', 'loco'], [])] for *q, a in qa: for i, e in enumerate(q): print('input{0}: {1}'.format(i + 1, e)) ans = f(*q) if ans != a: print(' [failed]') print(' output:', ans) print(' expected:', a) else: print(' [ok]') print(' output:', ans) print()
['Five', 'Four', 'One', 'Six', 'Two'], ['Five', 'Four', 'One', 'Three', 'Two'], ['Five', 'Four', 'Seven', 'Six', 'Three'], ['Five', 'Four', 'Seven', 'Six', 'Two'], ['Five', 'Four', 'Seven', 'Three', 'Two'], ['Five', 'Four', 'Six', 'Three', 'Two'], ['Five', 'One', 'Seven', 'Six', 'Three'], ['Five', 'One', 'Seven', 'Six', 'Two'], ['Five', 'One', 'Seven', 'Three', 'Two'], ['Five', 'One', 'Six', 'Three', 'Two'], ['Five', 'Seven', 'Six', 'Three', 'Two'], ['Four', 'One', 'Seven', 'Six', 'Three'], ['Four', 'One', 'Seven', 'Six', 'Two'], ['Four', 'One', 'Seven', 'Three', 'Two'], ['Four', 'One', 'Six', 'Three', 'Two'], ['Four', 'Seven', 'Six', 'Three', 'Two'], ['One', 'Seven', 'Six', 'Three', 'Two']])] for *q, a in qa: for i, e in enumerate(q): print('input{0}: {1}'.format(i + 1, e)) ans = [*map(list, f(*q))] if ans != a: print(' [failed]') print(' output:', ans) print(' expected:', a) else: print(' [ok]') print(' output:', ans) print()
(['abs', 'math.sin', 'lambda x: 3 * x / 2'], 3.1415, 1), (['math.sin', 'math.cos', 'lambda x: x * 2', 'lambda x: x ** 2'], 1, -0.404239153852), (['lambda z: z', 'lambda z: 1.0 * z / 13'], -1000, -76.9230769231), (['float'], 1000, 1000), (['abs'], -20, 20) ] for *q, a in qa: for i, e in enumerate(q): print('input{0}: {1}'.format(i + 1, e)) ans = round(f(*q), 6) if ans != round(a, 6): print(' [failed]') print(' output:', ans) print(' expected:', a) else: print(' [ok]') print(' output:', ans) print()
# Python3 from solution1 import rangeFloat as f qa = [ ([5], [0, 1, 2, 3, 4]), ([0.5, 7.5], [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5]), ([-1.1, 2.4, 0.3], [-1.1, -0.8, -0.5, -0.2, 0.1, 0.4, 0.7, 1, 1.3, 1.6, 1.9, 2.2]), ([5.6, 3.2], []), ([-3.2, -123, 10], []), ([-4], []), ([10.4, 3.2, -1.2], [10.4, 9.2, 8, 6.8, 5.6, 4.4, 3.2]), ([10, 10, 3], []), ([33.3], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]) ] for *q, a in qa: for i, e in enumerate(q): print('input{0}: {1}'.format(i + 1, e)) ans = [ round(i, 5) for i in f(*q) ] if ans != a: print(' [failed]') print(' output:', ans) print(' expected:', a) else: print(' [ok]') print(' output:', ans) print()
from solution1 import kthPermutation as f qa = [ ([1, 2, 3, 4, 5], 4, [1, 2, 4, 5, 3]), ([1, 2], 1, [1, 2]), ([11, 22, 31, 43, 56], 120, [56, 43, 31, 22, 11]), ([14, 25, 27, 29, 30, 40, 55, 89, 100, 239], 238, [14, 25, 27, 29, 40, 239, 100, 55, 89, 30]), ([14, 25, 27, 29, 30, 40, 55, 89, 100, 239], 3628800, [239, 100, 89, 55, 40, 30, 29, 27, 25, 14]), ([50, 100, 123, 789], 15, [123, 100, 50, 789]) ] for *q, a in qa: for i, e in enumerate(q): print('input{0}: {1}'.format(i + 1, e)) ans = list(f(*q)) if ans != a: print(' [failed]') print(' output:', ans) print(' expected:', a) else: print(' [ok]') print(' output:', ans) print()