Created
December 11, 2017 14:59
-
-
Save fedden/dfba81dfd8698d449ccfb20a76e328f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_fitness(fly): | |
# Get the indices that would sort the values | |
# flies position. This turns the flies continious | |
# position vector into a set of integers from 0 | |
# to len(fly). e.g | |
# [0.4, 0.53, 0.2, 0.7, 0.1] would turn into | |
# [4, 2, 0, 1, 3]. | |
fly_sorted_indices = np.argsort(fly) | |
# Turn indices into cards | |
fly_solution = fly_sorted_indices + 1 | |
# Sanity checks | |
assert np.sum(fly_solution) == 55 | |
assert len(np.unique(fly_solution)) == 10 | |
difference_one = abs(36 - np.sum(fly_solution[:5])) | |
difference_two = abs(360 - np.product(fly_solution[-5:])) | |
return difference_one + difference_two |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment