almost working learning algorithm