Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created Sep 8, 2020
Embed
What would you like to do?
def crossover(mom, dad, size):
index = random.randint(1, size - 1)
mom1 = mom & (2**index -1)
mom2 = mom & ((2**(size-index) -1) << index)
dad1 = dad & (2**index -1)
dad2 = dad & ((2**(size-index) -1) << index)
return mutate(mom1|dad2, size), mutate(dad1|mom2, size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment