[BL] Translate whiteboard pseudocode into code, works for sample data