Created
September 3, 2019 03:56
-
-
Save vznvzn/785ca51662723ec17c8de5597e2b58b9 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 f2(n) | |
return n.odd? ? (n * 3 + 1) / 2 : n / 2 | |
end | |
def out(a, a2 = {}, t = nil, ct = '') | |
fn = $fn.nil? ? 'out.txt' : $fn | |
k = a.keys | |
if ($f1.nil?) then | |
$f1 = File.open(fn, 'w') | |
$f1.puts(k.join("\t")) | |
f2 = File.open('gnuplot.cmd', 'w') | |
st = t.nil? ? 'unset title; ' : "set title \"#{t}\"; " | |
f2.puts("set ytics nomirror; set y2tics; set colors classic; set key top left box opaque; #{st}; plot \\") | |
(a.keys - ['t']).each \ | |
{ | |
|x| | |
next if (a2.member?(x) && a2[x].nil?) | |
m = a2.fetch(x, "(column('#{x}'))") | |
m += ' with line' if (!m.include?('with')) | |
f2.puts("'#{fn}' using #{m} title '#{x}' , \\") | |
} | |
f2.puts | |
f2.close | |
end | |
$f1.puts(a.values_at(*k).join("\t")) | |
$f1.flush | |
end | |
def remove(a, ks) | |
a = a.dup | |
ks.each { |x| a.delete(x) } | |
return a | |
end | |
def seq(n) | |
n1 = n | |
l = [] | |
begin | |
l << n | |
n = f2(n) | |
end while (n != 1) | |
return l | |
end | |
def fmt(x) | |
return remove(x, ['l']) | |
end | |
def axes2(x2) | |
return x2.inject({}) { |h, x| h.merge({x => 'axes x1y2' }) } | |
end | |
def sum(l) | |
return l.inject { |t, x| t + x } | |
end | |
def d(s) | |
c = s.split('').select { |x| x == '1' }.size | |
d = c.to_f / s.length | |
return d | |
end | |
def dp(x) | |
d(x.to_s(2)) >= 0.5 | |
end | |
c = 10 | |
l = File.open('db.txt').readlines.map { |x| Kernel.eval(x) }.select { |x| x['cm'] > c } | |
k = {} | |
l.each_with_index \ | |
{ | |
|x, j| | |
k[x['k']] = nil | |
l = seq(x['n']) | |
i = 0 | |
n = l[0] | |
c.times \ | |
{ | |
|x1| | |
dpx, dpn = [dp(x1), dp(n)] | |
m = {true => 1, false => 0}[dpx == dpn] | |
i += m | |
n *= 3 if (x1.odd?) | |
} | |
a = {'j' => j, 'i' => i, 'cm' => x['cm'], 'c' => k.size} | |
out(a, {'j' => nil, 'c' => nil, 'cm' => "(column('j')):(column('cm')):(column('c')) with line linecolor variable"}) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment