Note:
Testo rimosso dalla rev 1 e
Testo aggiunto nella rev2
Soluzione 04/03 di Luigi Panzeri
Peccato che memoize vada chiamata in un modo cosi’ strano.
def slowid (x,y)
sleep 5
x
end
def memoize(&proc)
if not defined? @cache
@cache = Hash.new
end
a = Proc.new { |x|
if @cache.has_key? x
@cache[x]
else
ret = proc.call *x
@cache[x] = ret
end
}
end
newslowid = memoize { |x| slowid *x}
puts (newslowid.call 3,2)
puts (newslowid.call 3,2)