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 f3(n)
- return n.odd? ? (n * 3 + 1) : n / 2
- end
- def load()
- fn = 'tmp/mix26/mixdb.txt'
- s = File.stat(fn)
- a = {'fn' => fn, 'ct' => s.ctime, 'mt' => s.mtime}
- l = (f = File.open(fn)).readlines.map { |x| Kernel.eval(x) }
- f.close
- a['l_in'] = l.size
- b = {}
- l.each { |x| b[x['n']] = x }
- l = b.values
- a['l_uniq'] = l.size
- $stderr.puts(a.inspect)
- return l
- end
- def seq(n)
- n1 = n
- l = [n]
- while (n >= n1 && n != 1)
- n = $f.call(n)
- l << n
- end
- cm = (0...l.size).max_by { |x| l[x] }
- return {'l' => l, 'cm' => cm, 'c' => l.size}
- end
- def sample(l, c)
- r = l.size / c
- l2 = *(0...l.size).select { |x| x % r == 0 }
- $stderr.puts(l2.size)
- return l.values_at(*l2)
- end
- def subclimb(l, c)
- (0...l.size).map \
- {
- |i|
- l1 = ((i + 1)...l.size).to_a
- j = l1.index { |x| l[x] < l[i] }
- next if (j.nil?)
- puts([i, c, l1[j] - i].join("\t"))
- }
- end
- tf = 1
- $f = [lambda { |x| f1(x) }, lambda { |x| f2(x) }, lambda { |x| f3(x) }][tf]
- l = load().map { |x| seq(x['n']) }.sort_by { |x| x['cm'] }
- sample(l, n = 500).reverse.each_with_index \
- {
- |x, i|
- subclimb(x['l'][0..x['cm']], n - i)
- }
Add Comment
Please, Sign In to add comment