Solve hanging lantern problem: Difference between revisions

Content added Content deleted
Line 1,393: Line 1,393:
===Directly computing the count===
===Directly computing the count===


If compute the count directly:
Compute the count directly:
<syntaxhighlight lang="ruby" line>Factorial = Hash.new{|h, k| h[k] = k * h[k-1] } # a memoized factorial
<syntaxhighlight lang="ruby" line>Factorial = Hash.new{|h, k| h[k] = k * h[k-1] } # a memoized factorial
Factorial[0] = 1
Factorial[0] = 1