# Genetic Algorithms in Elixir: N-Queens Ch4, pp89

**URL:** <https://forum.devtalk.com/t/genetic-algorithms-in-elixir-n-queens-ch4-pp89/4099>\
**Category:** PragProg Customers\
**Tags:** suggestion, book-genetic-algorithms-in-elixir\
**Created:** [16 November 2020 14:55 UTC](https://forum.devtalk.com/t/genetic-algorithms-in-elixir-n-queens-ch4-pp89/4099 "2020-11-16T14:55:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AgFox](https://forum.devtalk.com/user_avatar/forum.devtalk.com/agfox/32/2525_2.png) [@AgFox](https://forum.devtalk.com/u/AgFox)\
**Post date:** [16 November 2020 14:55 UTC](https://forum.devtalk.com/t/genetic-algorithms-in-elixir-n-queens-ch4-pp89/4099/1 "2020-11-16T14:55:38Z")

</div>

**Implementing the fitness function.**

> however they can still be in the same row

The genotype function generates an Elixir list of the columns that each queen is in (Enum.shuffle(0…7). A list 8 elements long consisting of all the digits 0-7 in some random order.  
Each element of the list represents the row for the queens column. As each element index must be unique (0, 1, 2, …,7) otherwise it would be a very strange list, each row can only contain one column.

Therefore there is no need to check that the rows only contain one queen.
