We solve a synthesis problem for linear arrays which consists in determining an array pattern belonging to a given mask. As a first step we assign a reference pattern F0 belonging to the mask, then we divide the interval [-π, π] of the space directions into small subintervals; this allows introducing a weight for each subinterval, thus determining a weighted mean-square distance between F0 and the generic array pattern. Minimizing this distance gives an array pattern whose values in each subinterval can be controlled by modifying the weights. Starting from a set of unitary weights we modify iteratively one weight at a time so as to suitably control the values of the pattern in the corresponding subinterval. This generates a sequence of array patterns which are closer and closer to the mask. A convergence test terminates the iteration and yields the solution.