reduce and whilst solutions