Skip to content

Instantly share code, notes, and snippets.

@Yuemashi
Created July 8, 2016 14:23
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 Yuemashi/0f70a09ef570809254e2be55eb69386b to your computer and use it in GitHub Desktop.
Save Yuemashi/0f70a09ef570809254e2be55eb69386b to your computer and use it in GitHub Desktop.
pop = Population[50,100]
pop.sort_by { |n| -fitness[n]}.take(1)
=>[[1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1]]
(0..100).each{pop = nextGeneration[pop]}
pop.sort_by { |n| -fitness[n]}.take(1)}
=>[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment