Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created July 24, 2015 19:59
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/bfe5aab4c8f03852dc2f to your computer and use it in GitHub Desktop.
Save vznvzn/bfe5aab4c8f03852dc2f to your computer and use it in GitHub Desktop.
out = {2 => nil}
seen = {1 => nil}
t = 0.0
c = 0
#2000.times \
loop \
{
l = out.keys.map { |x| [seen.keys.map { |y| (y - x).abs}.min, x] }
a = t / c
m, n = l.min_by { |x| (x[0] - a).abs }
t += m
c += 1
out.delete(n)
puts([n, out.size, m, a].join("\t"))
$stdout.flush
seen[n] = nil
l2 = []
l2 << n * 2
l2 << (n - 1) / 3 if (n % 3 == 1 && ((n - 1) / 3).odd?)
l2.each \
{
|x|
next if (seen.member?(x))
out[x] = nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment