Created
August 5, 2016 05:08
-
-
Save vznvzn/cdd3fb36860b03165de0bbd7a12b9880 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 | |
begin | |
l << (n = f1(n)) | |
end while (n >= n1 && n != 1) | |
return l | |
end | |
def d(s) | |
c = s.split('').select { |x| x == '1' }.size | |
d = s.empty? ? 0 : c.to_f / s.length | |
return (0.5 - d).abs, d | |
end | |
def stat(l, t) | |
return 0, 0, 0 if (l.empty? || t == 0) | |
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) | |
mx = l.max | |
return a / t, sd / t, mx.to_f / t | |
end | |
l = File.open("db.txt").readlines | |
m = ['w', 'cg', 'r'] | |
w = nil | |
f = nil | |
c = 0 | |
l.each_with_index \ | |
{ | |
|x, i| | |
z = Kernel.eval(x) | |
next if (z['cg'] < 20 || !m.member?(z['k'])) | |
l = seq2(z['n']) | |
if (z['k'] != w) then | |
f.close if (!w.nil?) | |
w = z['k'] | |
fn = "out_#{w}.txt" | |
f = File.open(fn, 'w') | |
p(fn) | |
end | |
t1 = t2 = 0 | |
l.each_with_index \ | |
{ | |
|x, i| | |
ns = x.to_s(2) | |
nl = ns.length | |
d = d(ns) | |
t1 += d[0] | |
t2 += d[1] | |
f.puts([c, l.size, i, x, ns, nl, d(ns), t1 / (i + 1), t2 / (i + 1)].join("\t")) | |
} | |
f.puts | |
c += 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment