Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created January 5, 2020 23:43
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/fe73ab0c7458cada1da891823c7c2902 to your computer and use it in GitHub Desktop.
Save vznvzn/fe73ab0c7458cada1da891823c7c2902 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 outin()
l = (f = File.open('gnuplot.cmd')).readlines
f.close
l.shift
i = 0
i += 1 while (l[i] != "eof\n" && i < l.size)
l[i..-1] = []
k = l.shift.split
l2 = l.map { |x| Hash[[k, x.split.map { |x| Kernel.eval(x) }].transpose] }
return l2
end
def count(ns)
l1 = seq(ns.to_i(2))
cg = l1.index { |x| x < l1[0] }
cg = l1.size if (cg.nil?)
cm = (0...cg).max_by { |x| l1[x] }
s = l1.map { |x| x.to_s(2) }.join
t0 = s.split('').select { |x| x == '1' }.size
t1 = s.length - t0
t = t0 + t1
z = t
return {'ns' => ns, 'cm' => cm, 'cg' => cg, 'c' => l1.size,
't' => t, 'z' => z, 't0' => t0, 't1' => t1, 'nw' => ns.length}
end
l = outin()
seen = {}
l.each { |x| seen[x['ns'].to_s] = nil }
tm = l[-1]['t']
p(tm)
l2 = seen.keys.map { |x| x.length }.uniq
a = {}
b = {}
50e3.to_i.times \
{
|i|
if (i % 1000 == 0) then
p(i)
puts("a = #{a.inspect}")
puts("b = #{b.inspect}")
puts
end
i += 1
w = l2[rand(l2.size)]
ns = '1' + (0...(w - 1)).map { rand(2).to_s }.join
x = count(ns)
if (x['t'] >= tm) then
b[w] = b.fetch(w, 0) + 1
next
end
a[w] = a.fetch(w, 0) + 1
raise(x.merge({'tm' => tm}).inspect) if (!seen.member?(ns))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment