And 54 lines of javascript: https://jsfiddle.net/06L845jx/127/
Original discussion: https://www.reddit.com/r/javascript/comments/9nihtw/a_simple...