Created
August 25, 2016 01:03
-
-
Save vznvzn/441629c16b29473d52b528cf26f2b820 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 seq2(n) | |
l = [n] | |
n1 = n | |
l << (n = f1(n)) while (n >= n1 && n != 1) | |
return l | |
end | |
def mx(n) | |
return {'mx' => seq2(n).size} | |
end | |
def d(s) | |
c = s.split('').select { |x| x == '1' }.size | |
d = c.to_f / s.length | |
return d | |
end | |
def stat(l) | |
return if (l.empty?) | |
t = t2 = 0 | |
l.each \ | |
{ | |
|x| | |
t += x | |
t2 += x ** 2 | |
} | |
c = l.size | |
a = t.to_f / c | |
z = t2.to_f / c - a ** 2 | |
sd = Math.sqrt(z < 0 ? 0 : z) | |
return l.size, a, sd, l.max, l.min | |
end | |
l = [{'n' => 1, 'p' =>0}.merge(mx(1))] | |
a = {} | |
loop \ | |
{ | |
x = l.delete_at(rand(l.size)) | |
p = x['p'] + 1 | |
n = x['n'] | |
x1 = x.dup | |
x1['p'] = p | |
l.push(x1) | |
x2 = {} | |
n |= (1 << p) | |
x2['n'] = n | |
x2['p'] = p | |
x2.merge!(mx(n)) | |
if (x2['mx'] > x['mx']) then | |
l.push(x2) | |
# j = p | |
j = x2['mx'] | |
a[p] = a.fetch(p, []) + [x2] | |
end | |
$stderr.puts(l.size) if (l.size % 100 == 0) | |
break if (l.size == 100000) | |
} | |
a.keys.sort.each \ | |
{ | |
|i| | |
l = a[i].map { |x| d(x['n'].to_s(2)) } | |
puts(([i] + stat(l)).join("\t")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment