Created
July 27, 2020 05:21
-
-
Save vznvzn/1f0cf4f09f84ebedfb48192a847d6b84 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 seqg(n) | |
n1 = n | |
l = [n1] | |
while (n != 1 && n >= n1) | |
n = f2(n) | |
l << n | |
end | |
return l | |
end | |
def outa(f, l, a = {}, t = '') | |
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 left opaque; set title '#{t}'; ") | |
# f.puts("set ytics nomirror; set y2tics;") | |
f.puts("plot \\") | |
k, ct = [k - ['t'], "(column('t')):"] if (k.member?('t')) | |
k.each \ | |
{ | |
|x| | |
next if (a.member?(x) && a[x].nil?) | |
opt = a.fetch(x, '') | |
opt += ' lw 2 ' if (!opt.include?('lw')) | |
opt += ' with line ' if (!opt.include?('with')) | |
f.puts("'$dat' using #{ct}(column('#{x}')) #{opt} title '#{x}',\\") | |
} | |
f.puts | |
# f.puts("reset; pause -1;") | |
end | |
def outafn(l, a = {}, fn = nil) | |
outa(f = File.open(fn.nil? ? 'gnuplot.cmd' : fn, 'w'), l, a) | |
f.close | |
end | |
def len(ns, p) | |
l = ns.split(p) | |
l = [] if (l.nil?) | |
l.shift if (l[0] == '') | |
return l.map { |x| x.length } | |
end | |
def len1(ns) | |
return len(ns, /0+/) | |
end | |
def len0(ns) | |
return len(ns, /1+/) | |
end | |
def len01(ns) | |
return len0(ns), len1(ns) | |
end | |
def pos(l, b) | |
x1 = 0 | |
l.map { |x| x1 += 1; [x, x1, x1.to_f / l.size, b] } | |
end | |
def pmx01(ns) | |
l0, l1 = len01(ns) | |
pmx0 = pos(l0, 0).max_by { |x| x[0] } | |
pmx1 = pos(l1, 1).max_by { |x| x[0] } | |
return pmx0, pmx1 | |
end | |
def d(s) | |
c = s.split('').select { |x| x == '1' }.size | |
d = c.to_f / s.length | |
return d | |
end | |
def pmx(l) | |
p = l.map { |x| x % 2 }.join | |
pmx0, pmx1 = pmx01(p) | |
return {'pmx1' => pmx1[0], 'pmx0' => pmx0[0], 'pmxd10' => pmx1[0] - pmx0[0]} | |
end | |
def mx01(ns) | |
l0, l1 = len01(ns) | |
return {'mx0' => l0.max, 'mx1' => l1.max } | |
end | |
def mx(l) | |
l1 = l.map { |x| mx01(x.to_s(2)) } | |
mx0 = l1.map { |x| x['mx0'] }.max | |
mx1 = l1.map { |x| x['mx1'] }.max | |
return {'mx0' => mx0, 'mx1' => mx1, 'mxd10' => mx1 - mx0} | |
end | |
l1 = [] | |
(5..2000).each \ | |
{ | |
|i| | |
ns = '1' * i | |
n = ns.to_i(2) | |
l = seqg(n)[i..-1] | |
l1 << pmx(l).merge(mx(l)) | |
$stderr.puts(i) if (i % 100 == 0) | |
} | |
outafn(l1, {'pmxd10' => 'with impulse', 'mxd10' => 'lt 7'}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment