Created
July 1, 2010 02:57
-
-
Save anatman/459503 to your computer and use it in GitHub Desktop.
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 dsh(un, va) | |
(va.size - 1).downto(1) {|j| va[j] = va[0 .. j].inject(1) { |pr, it| pr * it } } | |
ar = un.zip va | |
hs = {} | |
ar.each {|i| hs[i[0]] = i[1] } | |
hs | |
end | |
yds = dsh([:yd, :ft, :in], [1, 3, 12]) | |
puts yds[:in] / yds[:ft] * 1.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check out my gist http://gist.github.com/7628cf7a4745c9179c66 , does it actually do the same in like 15 lines what yours does in 7? I think the optimal solution is somewhere between this one and mine... but I am not familiar enough with zip and inject to be able to read it (to trace the operations).