Whiteboard exercise written out as an R program