Cross-post: How would I create this solution algorithm using pseudocode?