Last active
December 28, 2015 07:48
-
-
Save straypacket/7466674 to your computer and use it in GitHub Desktop.
Codility - Number-of-disc-intersections Still working on it :/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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