Discrete function: efficient solution

Solve a problem with only one bypass of input data list.