Created
September 2, 2016 00:56
-
-
Save vznvzn/083f383b7073959d1f0a3cadd0c5c6ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def f1(n) | |
n = (n * 3 + 1) / 2 while (n % 2 == 1) | |
n /= 2 while (n % 2 == 0) | |
return n | |
end | |
def seq(n) | |
l = [n] | |
l << (n = f1(n)) while (n != 1) | |
return l | |
end | |
def seq2(n) | |
l = [n] | |
n1 = n | |
l << (n = f1(n)) while (n >= n1 && n != 1) | |
return l | |
end | |
def d(s) | |
c = s.split('').select { |x| x == '1' }.size | |
d = c.to_f / s.length | |
return d | |
end | |
def val(z) | |
n = z['n'] | |
l = seq(n) | |
cm = (0...l.size).max_by { |x| l[x] } | |
ns = n.to_s(2) | |
d = d(ns) | |
nl = ns.length | |
return z.merge({'cm' => cm, 'nl' => nl, 'd' => d, 'by' => nl - cm}) | |
end | |
def hard(c) | |
l = [val({'n' => 1, 'p' =>0})] | |
c.times \ | |
{ | |
l.sort_by! { |x| [x['by'], x['d']] } | |
x = l.delete_at(rand([l.size, 100].min)) | |
p = x['p'] + 1 | |
l.push(x.merge('p' => p)) | |
l.push(val({'n' => x['n'] | (1 << p), 'p' => p})) | |
$stderr.puts([l.size, x].inspect) | |
} | |
return l | |
end | |
l = hard(5000) | |
l[0...10].each { |x| $stderr.puts(x.inspect) } | |
$stderr.puts(l[0].keys.inspect) | |
l.sort_by! { |x| x['n'] }.each { |x| p(x.values) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment