Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created September 2, 2015 23:11
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/40c82df99b4d43f15a05 to your computer and use it in GitHub Desktop.
Save vznvzn/40c82df99b4d43f15a05 to your computer and use it in GitHub Desktop.
def dist(l)
l = l.sort
t = 0
(1...l.size).each { |x| t += l[x] - l[x - 1] }
return t.to_f / (l.size - 1)
end
l = [1]
seen = {1 => nil}
2000.times \
{
|n|
d = dist(seen.keys)
j = (0...l.size).min_by { |x| (dist(seen.keys + [l[x]]) - d).abs }
x = l.delete_at(j)
puts([n, x, d].join("\t"))
$stdout.flush
# x = l.shift
([x * 2] + ((x % 3 == 1 && ((x - 1) / 3).odd?) ? [(x - 1) / 3] : [])).each \
{
|z|
next if (seen.member?(z))
l << z
seen[z] = nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment