Now for a slightly more rubyish implementation using partitions