R bloggers

The Twitter Waterflow Problem

FavoriteLoadingAdd to favorites

(This article was first published on Blog, and kindly contributed to R-bloggers) Nathan Eastwood, Data Scientist I was recently introduced to the Twitter Waterflow Problem and I decided it was interesting enough to try and complete the challenge in R. Consider the following picture: This plot shows a series of walls and empty valleys. We can represent this picture by an array of integers, where the value at each index is the height of the wall. So in this case, the array of integers can be defined as: wall <- c(2, 5, 1, 2, 3, 4, 7, 7, 6) Now imagine it rains. How much water is going to be accumulated in puddles between walls? No puddles are formed at edges of the wall and water is considered to simply run off the edge. We count volume in square blocks…
Original Post: The Twitter Waterflow Problem