Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created July 27, 2015 21:18
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/548349809e7418d1978a to your computer and use it in GitHub Desktop.
Save vznvzn/548349809e7418d1978a to your computer and use it in GitHub Desktop.
def hist(l, i)
return if (l.size == 1)
l = l.dup
l.map! { |x| x.to_s(2).length }
mn = l.min
mx = l.max
r = (mx - mn)
w = 100
h = [0] * (w + 1)
l.each { |x| h[((x.to_f - mn) / r * w).to_i] += 1 }
m = (0..w).max_by { |x| h[x] }
h.each_with_index { |y, x| puts([x - m, y, i].join("\t")) }
puts
end
l = [1]
seen = {}
ARGV[0].to_i.times \
{
|i|
l2 = []
l.each \
{
|x|
next if (seen.member?(x))
seen[x] = nil
l2 << x * 2
l2 << (x - 1) / 3 if (x % 3 == 1 && ((x - 1) / 3).odd?)
}
l = l2
hist(l, i)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment