Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created August 11, 2015 21:54
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/6bad794abbd23082b415 to your computer and use it in GitHub Desktop.
Save vznvzn/6bad794abbd23082b415 to your computer and use it in GitHub Desktop.
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
end
def prime(p)
n = 3
sq = Math.sqrt(p)
while (n <= sq)
return false if (p % n == 0)
n += 2
end
return true
end
def out(f, l)
f = File.open(f, 'w')
l.reverse.each_with_index \
{
|x, c|
200.times \
{
|i|
f.puts (power(x, i) + [c]).join("\t")
}
f.puts
}
f.close
end
l = []
l2 = []
t = 50
n = 3
while (l.size < t || l2.size < t)
if (prime(n)) then
l << n
else
l2 << n if (l2.size < l.size)
end
n += 2
end
out('out1.txt', l)
out('out2.txt', l2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment