Press the green flag to see, or, see inside for some in-depth detail. And explanations!
All code by me.