Skip to content

Instantly share code, notes, and snippets.

@straypacket
Last active December 28, 2015 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save straypacket/7466674 to your computer and use it in GitHub Desktop.
Save straypacket/7466674 to your computer and use it in GitHub Desktop.
Codility - Number-of-disc-intersections Still working on it :/
def solution(a)
radii = {}
a.count.times do |c|
(c-a[c]..c+a[c]).to_a.each do |r|
radii[r] = [] if !radii.key?(r)
radii[r] << c
end
end
combs = []
radii.keys.each do |k|
combs << [k].product(radii[k]-[k]) if k >= 0 and k <= (a.length-1)
end
res = combs.flatten(1).map { |x| x.sort}.uniq
return res.count
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment