Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created November 10, 2018 05:39
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/1cd4868ced0b92a1ff89061e2b771699 to your computer and use it in GitHub Desktop.
Save vznvzn/1cd4868ced0b92a1ff89061e2b771699 to your computer and use it in GitHub Desktop.
def fmt(l, f)
w = l.max_by { |x| x.length }.length
f.puts("set colors classic; \\")
f.puts("plot \\")
f.puts("[0:#{w}][0:#{l.size - 1}] '-' matrix 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")
f.puts("pause -1;")
end
f = File.open(fn = "gnuplot1.cmd", 'w')
f.puts("set palette negative grayscale; unset colorbox;")
l = (f1 = File.open('out1.txt')).readlines.map { |x| x.strip }
f1.close
fmt(l, f)
l = l.map \
{
|x|
n = x.reverse.to_i(2) * 2 - 1
raise if (n % 3 != 0)
(n / 3).to_s(2).reverse
}
fmt(l, f)
f.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment