Created
November 23, 2019 03:00
-
-
Save vznvzn/4d508e88d4e8afb0b0bb5e1e65178a41 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 dense(w, d) | |
w2 = w - 1 | |
a = (0...w2).to_a | |
s = '0' * w2 | |
(1..(d * w - 1)).map { a.delete_at(rand(a.size)) }.each { |x| s[x, 1] = '1' } | |
return ('1' + s) | |
end | |
def seq(n) | |
n1 = n | |
l = [] | |
begin | |
l << n | |
n = f2(n) | |
end while (n != 1) | |
return l | |
end | |
def fmt1(l, f) | |
w = l.max_by { |x| x.length }.length | |
f.puts("set colors classic; set ytics nomirror; set y2tics; set key top left opaque;\\") | |
f.puts("plot \\") | |
f.puts("[0:#{w}][0:#{l.size - 1}] '-' matrix using 1:2:3 with image title ''") | |
l.each_with_index \ | |
{ | |
|z, i| | |
c = w - z.length | |
z[z.length...w] = '0' * c | |
f.puts(z.split('').join(' ')) | |
} | |
f.puts("eof") | |
f.puts("eof") | |
end | |
def grid(l) | |
f = File.open(fn = "gnuplot1.cmd", 'w') | |
f.puts("set palette negative grayscale; unset colorbox;") | |
fmt1(l.map { |x| x.reverse }, f) | |
f.close | |
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 bottom right; 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 | |
l = [] | |
200.times \ | |
{ | |
ns = dense(200, 0.5) | |
l << seq(ns.to_i(2)) | |
} | |
l.sort_by! { |x| x[10] } | |
grid(l.map { |x| x[0].to_s(2) }) | |
outa(f = File.open('gnuplot.cmd', 'w'), l.map { |x| { 'x0' => Math.log(x[0]) } }) | |
f.close | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment