We present a non-parametric technique to infer the projected-mass distribution of a gravitational lens system with multiple strong-lensed images. The technique involves a dynamic grid in the lens plane on which the mass distribution of the lens is approximated by a sum of basis functions, one per grid cell. We used the projected mass densities of Plummer spheres as basis functions. A genetic algorithm then determines the mass distribution of the lens by forcing images of a single source, projected back onto the source plane, to coincide as well as possible. Averaging several tens of solutions removes the random fluctuations that are introduced by the reproduction process of genomes in the genetic algorithm and highlights those features common to all solutions. Given the positions of the images and the redshifts of the sources and the lens, we show that the mass of a gravitational lens can be retrieved with an accuracy of a few percent and that, if the sources sufficiently cover the caustics, the mass distribution of the gravitational lens can also be reliably retrieved. A major advantage of the algorithm is that it makes full use of the information contained in the radial images, unlike methods that minimise the residuals of the lens equation, and is thus able to accurately reconstruct also the inner parts of the lens.