Guest User

Untitled

a guest
Aug 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. def f1(n)
  2. n = (n * 3 + 1) / 2 while (n.odd?)
  3. n /= 2 while (n.even?)
  4. return n
  5. end
  6.  
  7. def f2(n)
  8. return n.odd? ? (n * 3 + 1) / 2 : n / 2
  9.  
  10. end
  11.  
  12. def f3(n)
  13. return n.odd? ? (n * 3 + 1) : n / 2
  14.  
  15. end
  16.  
  17. def load()
  18. fn = 'tmp/mix26/mixdb.txt'
  19. s = File.stat(fn)
  20. a = {'fn' => fn, 'ct' => s.ctime, 'mt' => s.mtime}
  21. l = (f = File.open(fn)).readlines.map { |x| Kernel.eval(x) }
  22. f.close
  23.  
  24. a['l_in'] = l.size
  25.  
  26. b = {}
  27. l.each { |x| b[x['n']] = x }
  28. l = b.values
  29.  
  30. a['l_uniq'] = l.size
  31. $stderr.puts(a.inspect)
  32. return l
  33.  
  34. end
  35.  
  36. def seq(n)
  37.  
  38. n1 = n
  39. l = [n]
  40. while (n >= n1 && n != 1)
  41. n = $f.call(n)
  42. l << n
  43. end
  44. cm = (0...l.size).max_by { |x| l[x] }
  45. return {'l' => l, 'cm' => cm, 'c' => l.size}
  46. end
  47.  
  48. def sample(l, c)
  49.  
  50. r = l.size / c
  51. l2 = *(0...l.size).select { |x| x % r == 0 }
  52. $stderr.puts(l2.size)
  53. return l.values_at(*l2)
  54.  
  55. end
  56.  
  57. def subclimb(l, c)
  58.  
  59. (0...l.size).map \
  60. {
  61. |i|
  62. l1 = ((i + 1)...l.size).to_a
  63. j = l1.index { |x| l[x] < l[i] }
  64.  
  65. next if (j.nil?)
  66. puts([i, c, l1[j] - i].join("\t"))
  67. }
  68.  
  69. end
  70.  
  71.  
  72. tf = 1
  73.  
  74. $f = [lambda { |x| f1(x) }, lambda { |x| f2(x) }, lambda { |x| f3(x) }][tf]
  75.  
  76.  
  77. l = load().map { |x| seq(x['n']) }.sort_by { |x| x['cm'] }
  78.  
  79. sample(l, n = 500).reverse.each_with_index \
  80. {
  81. |x, i|
  82. subclimb(x['l'][0..x['cm']], n - i)
  83. }
Add Comment
Please, Sign In to add comment