The algorithm looks like a simple neural network with one neuron. Normally, neural networks get trained by providing the input and output data to adjust the weights. In this case, it looks like the user figured out the weights by trial and error.