Created
January 11, 2020 03:45
-
-
Save vznvzn/9ea2c814ef9c0484231ad04a9728a572 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 seq(n) | |
n1 = n | |
l = [] | |
begin | |
l << n | |
n = f2(n) | |
end while (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 outa(f, l, a = {}, c = '') | |
f.puts('$dat << eof') | |
k = l[0].keys | |
f.puts(k.join("\t")) | |
l.each { |x| f.puts(x.values.join("\t")) } | |
f.puts('eof') | |
f.puts("set colors classic; set key top right opaque; ") | |
f.puts("set ytics nomirror; set y2tics;") | |
f.puts("plot \\") | |
k.each \ | |
{ | |
|x| | |
next if (a.member?(x) && a[x].nil?) | |
f.puts("'$dat' using #{c}(column('#{x}')) with line #{a.fetch(x, '')} lw 2 title '#{x}',\\") | |
} | |
f.puts | |
# f.puts("reset; pause -1;") | |
end | |
l = File.open('db.txt').readlines.map { |x| Kernel.eval(x) } | |
ks = l.map { |x| x['k'] }.uniq | |
x1 = 0 | |
l2 = [] | |
ks.each \ | |
{ | |
|k| | |
x = l.select { |x| x['k'] == k }.max_by { |x| x['cm'] } | |
n = x['n'] | |
l1 = seq(n).select { |x| x.odd? } | |
y3 = 0 | |
l1.each \ | |
{ | |
|x| | |
d3 = d(n.to_s(2)) | |
y3 += (d3 < 0.5) ? -1 : 1 | |
l2 << {'d3' => d3, 'x1' => x1, 'y1' => x.to_s(2).length, 'y3' => y3} | |
x1 += 1 | |
n *= 3 | |
} | |
x1 += 200 | |
l2 << {} | |
} | |
outa(File.open('gnuplot.cmd', 'w'), l2, {'x1' => nil, 'd3' => 'axes x1y2'}, "(column('x1')):") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment