Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 0.31 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. require 'pp'
  2. def partition(i, tau)
  3.   if(i == 0)
  4.     1
  5.   else
  6.     pk_last = partition(i-1, tau)
  7.     pk_this = ((1/(1.0-tao)) * pk_last).ceil + 1
  8.   end
  9. end
  10.  
  11. tau = 0.3
  12. 0.upto(6) do |i|
  13.   pp [i, partition(i,tau)]
  14. end
  15.  
  16. puts "should be: 1, 3, 6, 10, 15, 22, 31, 43, 59, 80"
  17.  
  18. # but it is wrong it is rather: 1 3 6 10 16 24 36