Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@christianbundy
Created April 30, 2015 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianbundy/120c078ddb026e154263 to your computer and use it in GitHub Desktop.
Save christianbundy/120c078ddb026e154263 to your computer and use it in GitHub Desktop.
def answer(x):
len_x = len(x)
modifier = (sum(x) / float(len_x)) % 1
modifier = modifier if modifier <= 0.5 else 1 - modifier
return int(len_x - len_x * modifier)
def expect(expected, actual):
assert expected is actual, \
"expected: {}, actual {}".format(expected, actual)
def hard_test(answer):
tests = [
[[1, 4, 1], 3],
[[1, 2], 1],
[[50, 50, 50, 54], 4],
[[50, 50, 50, 53], 3],
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 10],
[[0, 0, 0, 0], 4],
[[0, 0, 0, 1], 3],
[[0, 1, 3], 2]
]
for t in tests:
expect(t[1], answer(t[0]))
print('✓')
hard_test(answer)
def fuzz_test(answer):
import random
cars = random.randrange(2, 100)
rabbits = random.randrange(0, 10 ^ 6)
fuzz_test(answer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment