Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created May 23, 2015 21:05
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/e0ce2437b9738d7e5d4c to your computer and use it in GitHub Desktop.
Save vznvzn/e0ce2437b9738d7e5d4c to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby1.8
def f(n)
l = []
l2 = []
t = 0.0
while (n != 1)
l2 << n
t += n
l << t
n = (n % 2 == 0) ? n / 2 : n * 3 + 1
end
return l, l2
end
def deform(n, p)
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, l4 = f(n)
l5 = []
j = 0
p.times \
{
|i|
r = l2[i] / l2[-1]
d = 0
while ((l3[j] / l3[-1]) < r)
d += l4[j]
j += 1
end
l5 << d
}
return l5
end
t, p = ARGV.map { |x| x.to_i }
n = 3
l2 = [0] * p
t.times \
{
l = deform(n, p)
l.each_with_index { |x, i| l2[i] += x }
n += 2
}
l2.each { |x| p(x.to_f / t) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment