January 2019
Intermediate to advanced
390 pages
9h 16m
English
In this program, we use genetic algorithms to guess a word. The genetic algorithm will know the number of letters in the word and will guess those letters until it finds the right answer. We decide to represent the genes as a single alphanumeric character; strings of these characters thus constitute a chromosome. And our fitness function is the sum of the characters matching in the individual and the right word:
import stringimport randomfrom deap import base, creator, tools
Read now
Unlock full access