That said, some minor changes bring down the time to a fraction of the original:
size = 10 ** 5
a = (1..size).map { {rand(1000), rand(1000)} }
def dist(u, v)
(u[0] - v[0]).abs + (u[1] - v[1]).abs
end
a.each_with_index { |u, i|
print "\r#{i}" if i % 100 == 0
((i + 1)..(a.size - 1)).each { |v|
dist(u, a[v]) < 3
}
}
takes
real 0m22,396s
user 0m22,395s
sys 0m0,001s
on my machine where the original took 1.35 minutes