Created
January 17, 2009 13:06
-
-
Save ayucat/48339 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
# calc distances! | |
# example: | |
# %w[111 200 311 222 400].map { |s| printf "%s => %5.3f " s, o2d(s) } | |
def o2d(s) | |
return 0.0 unless s.is_a?(String) && s.size == 3 | |
1 / (((0..2).to_a.inject(0) { |x, i| x += s[i,1].to_f**2 }) ** 0.5) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment