Motivated by a potential application in economics, we investigate a simple dynamical scheme to produce planted solutions in optimization problems with continuous variables. We consider the perceptron model as a prototypical model. Starting from random input patterns and perceptron weights, we find a locally optimal assignment of weights by gradient descent; we then remove misclassified patterns (if any), and replace them by new, randomly extracted patterns. This “remove and replace” procedure is iterated until perfect classification is achieved. We call this procedure “self-planting” because the “planted” state is not pre-assigned but results from a co-evolution of weights and patterns. We find an algorithmic phase transition separating a region in which self-planting is efficiently achieved from a region in which it takes exponential time in the system size. We conjecture that this transition might exist in a broad class of similar problems.