A Stratified Solution

Was enjoying the challenge of this, and wanted to see if I could work out the stratified version of this algorithm. 

Not sure if there's value in having the solution around, if not, feel free to close, no hurt feelings :)