Created
August 17, 2015 21:28
-
-
Save vznvzn/beb8720943e83c15c80c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def power(x, p) | |
n = n1 = x ** p | |
w = n.to_s(2).length | |
c = 0 | |
while (n != 1 && n >= n1) | |
n = n * 3 + 1 if (n.odd?) | |
n /= 2 while (n.even?) | |
c += 1 | |
end | |
return w, c, dense(n1), dense(x) | |
end | |
def dense(n) | |
s = n.to_s(2) | |
c = 0 | |
s.length.times \ | |
{ | |
|i| | |
c += s[i, 1].to_i | |
} | |
return c.to_f / s.length | |
end | |
def out(x, c) | |
w = x.to_s(2).split(/0+/) | |
l = [] | |
50.times \ | |
{ | |
|i| | |
l << power(x, i * 2 + 1) + [w[-1].length] | |
} | |
return l | |
end | |
t = 1024 + 3 | |
l = [] | |
50.times \ | |
{ | |
|i| | |
l += out(t, i) | |
t += 4 | |
} | |
c = ARGV[0].to_i | |
l.shuffle.sort_by { |x| x[c] }.each { |x| puts(x.join("\t")) } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment