Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created February 4, 2020 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vznvzn/06bd725333e49229baa889f707319442 to your computer and use it in GitHub Desktop.
Save vznvzn/06bd725333e49229baa889f707319442 to your computer and use it in GitHub Desktop.
def f2(n)
return n.odd? ? (n * 3 + 1) / 2 : n / 2
end
def seq(n)
n1 = n
l = [n1]
while (n != 1)
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.each \
{
|x|
next if (a.member?(x) && a[x].nil?)
f.puts("'$dat' using (column('#{x}')) with line #{a.fetch(x, '')} lw 2,\\")
}
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
l = []
(1..2000).each \
{
|nw|
ns = '1' * nw
l1 = seq(ns.to_i(2))
cg = l1.index { |x| x < l1[0] }
cg = l1.size - 1 if (cg.nil?)
cm = (0..cg).max_by { |x| l1[x] }
l << {'nw' => nw, 'cm' => cm, 'cmnw' => cm - nw, 'cg' => cg, 'cgnw' => cg - nw}
$stderr.puts(nw) if (nw % 10 == 0)
}
outafn(l, {'cmnw' => 'axes x1y2'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment