Algorithm for Optimal Decision Making