this line confuses me (and I see it was in the original code as well)

You can do this probably easier with: `values.each_with_index { |value, x| ... }`