DEV Community

Cover image for ---------------------------------
Tariq Mehmood
Tariq Mehmood

Posted on



Implement the following problem using genetic algorithms in any programming language
(e.g. C++/python/java):

Suppose your “individuals” are 32-bit computer words. You want a string in which all the bits are ones.

Here’s how you can do it:

  • Create 100 randomly generated computer word
  • Repeatedly do the following:
  • Count the 1 bits in each word
  • Exit if any of the words have all 32 bits set to 1
  • Keep the ten words that have the most 1s (discard the rest)
  • From each word, generate 9 new words as follows:
  • Pick a random bit in the word and toggle (change) it
  • Note that this procedure does not guarantee that the next “generation” will have more 1 bits, but it’s likely.


Top comments (1)

tariqmehmood profile image
Tariq Mehmood

Please help me to solve this algorithm. I am stuck with this algo.

Regex for lazy developers

regex for lazy devs

You know who you are. Sorry for the callout 😆