Skip to content

Instantly share code, notes, and snippets.

@anatman
Created July 1, 2010 02:57
Show Gist options
  • Save anatman/459503 to your computer and use it in GitHub Desktop.
Save anatman/459503 to your computer and use it in GitHub Desktop.
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
@kotp
Copy link

kotp commented Jul 2, 2010

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment