Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def f1(n)
- n = (n * 3 + 1) / 2 while (n.odd?)
- n /= 2 while (n.even?)
- return n
- end
- def f2(n)
- return n.odd? ? (n * 3 + 1) / 2 : n / 2
- end
- def avg(l)
- return 0 if (l.empty?)
- t = 0
- l.each { |x| t += x }
- return t.to_f / l.size
- end
- def total(l)
- t = 0
- l.each { |x| t += x }
- return t
- end
- def h(n, l0, l1)
- ns = n.to_s(2)
- nl = ns.length
- l1.concat(ns.split(/0+/).map { |x| x.length })
- l0.concat([ns.split(/1+/)[1..-1]].compact.flatten.map { |x| x.length })
- end
- def count(x)
- n = n1 = x['n']
- l = [n]
- while (n >= n1 && n != 1)
- n = {'packed' => true, 'unpacked' => false}[$w] ? f1(n) : f2(n)
- l << n
- end
- cm = (0...l.size).max_by { |x| l[x] }
- l0 = []
- l1 = []
- l[0..cm].each \
- {
- |n|
- h(n, l0, l1)
- }
- return l0, l1
- end
- # $w = 'packed'
- $w = 'unpacked'
- l = File.open('tmp/mixdb.txt').readlines.map { |x| Kernel.eval(x) }
- j = 0
- at = {}
- l = l.sort_by { |x| x['cm'] }.reverse
- c = 500
- c.times \
- {
- |i|
- j = (i.to_f / (c - 1) * (l.size - 1)).to_i
- l0, l1 = count(l[j])
- l1.sort!
- l1 = l1.select { |x| x >= 9 }
- l1.each_with_index \
- {
- |y, x|
- puts([x.to_f / l1.size, y, c - i].join("\t"))
- }
- puts
- }
Add Comment
Please, Sign In to add comment