Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created May 21, 2015 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vznvzn/cc66908438fdf3431501 to your computer and use it in GitHub Desktop.
Save vznvzn/cc66908438fdf3431501 to your computer and use it in GitHub Desktop.
def f(n)
l = []
t = 0.0
while (n != 1)
t += n
l << t
n = n.even? ? n / 2 : n * 3 + 1
end
return l
end
def dat(n)
l = []
$p.times \
{
|i|
l[i] = ($p - i).to_f / $p
}
l2 = []
t = 0
l.each_with_index \
{
|x, i|
t += x
l2[i] = t
}
l3 = f(n)
j = 0
$p.times \
{
|i|
r = l2[i] / l2[-1]
j += 1 while ((l3[j] / l3[-1]) < r)
puts([i, l3[j], j].join(','))
}
# puts
end
$p = 100
n = 3
puts("i,t,z")
20.times { dat(n); n += 2 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment