On Scratch (Picture above)

Answer:
see image below
Explanation:
This is a bit cumbersome, but it does the job. Not sure if it can be done much more efficiently. For these kind of operations, you'd be better off with a text based programming language.