Scott Logic interview question

Coding question with follow-up questions about optimising, logical puzzles, design patterns.