Created
December 21, 2019 05:26
-
-
Save vznvzn/4ecc030365615768e3632c09db3ec9ff 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 outin() | |
l = File.open('out.txt').readlines | |
k = l.shift.split | |
l2 = l.map { |x| Hash[[k, x.split.map { |x| Kernel.eval(x) }].transpose] } | |
return l2 | |
end | |
def outa(f1, l, a = {}, t = '') | |
f = f1.nil? ? File.open('gnuplot.cmd', 'w') : f1 | |
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 bottom right opaque; set title '#{t}'; ") | |
# f.puts("set ytics nomirror; set y2tics;") | |
f.puts("plot \\") | |
(k - ['t']).each \ | |
{ | |
|x| | |
next if (a.member?(x) && a[x].nil?) | |
f.puts("'$dat' using (column('t')):(column('#{x}')) with line #{a.fetch(x, '')} lw 2 title '#{x}',\\") | |
} | |
f.puts | |
# f.puts("reset; pause -1;") | |
f.close if (f1.nil?) | |
end | |
def lenx(ns, p) | |
l = ns.split(p) | |
l = [] if (l.nil?) | |
l.shift if (l[0] == '') | |
return l.map { |x| x.length } | |
end | |
def len01x(ns) | |
return lenx(ns, /0+/), lenx(ns, /1+/) | |
end | |
def seq1(n) | |
n1 = n | |
l = [n1] | |
while (n != 1) | |
n = f2(n) | |
l << n | |
end | |
return l.select { |x| x.odd? } | |
end | |
def d(s) | |
c = s.split('').select { |x| x == '1' }.size | |
d = c.to_f / s.length | |
return d | |
end | |
def e(ns) | |
return len01x(ns).flatten.size.to_f / ns.length | |
end | |
l = outin() | |
l.sort_by! { |x| x['cg'] } | |
l3 = [] | |
$t = 0 | |
(1..10).each \ | |
{ | |
|j| | |
x = l[-j] | |
l1 = seq1(x['n']) | |
l2 = l1.map { |x| x.to_s(2) } | |
cg = l1.index { |x| x < l1[0] } | |
cg = l1.size if (cg.nil?) | |
cm = (0...cg).max_by { |x| l1[x] } | |
r = [cm, cg - cm].min | |
sl1 = l2[0...r] | |
sr1 = l2[(cm + 1)..(cm + r)] | |
(1..80).each \ | |
{ | |
|i| | |
sl = sl1.map { |x| x[-i, 1] }.join | |
sr = sr1.map { |x| x[-i, 1] }.join | |
d1 = d(sl) | |
d2 = d(sr) | |
e1 = e(sl) | |
e2 = e(sr) | |
l3 << {'t' => $t += 1, 'd1' => d1, 'd2' => d2, 'd21' => d2 - d1, | |
'e1' => e1, 'e2' => e2, 'e21' => e2 - e1, | |
'de1' => d1 - e1, 'de2' => d2 - e2} | |
} | |
l3 << {} | |
$t += 20 | |
} | |
outa(nil, l3) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment