Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created November 23, 2015 23:49
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/55fabd1e2f8cb4eee171 to your computer and use it in GitHub Desktop.
Save vznvzn/55fabd1e2f8cb4eee171 to your computer and use it in GitHub Desktop.
def adv(n)
l = []
s = ''
while (n != 1)
l << n
while (n.odd?)
n = (n * 3 + 1) / 2
s << '1'
end
while (n.even?)
n /= 2
s << '0'
end
end
return 0, l, s
end
def f(l1)
i = l1[0]
return 0 if (i == l1[1].size)
$t += l1[1][i]
j = i + 10
j = -1 if (j >= l1[1].size)
# l1[1][j]
l1[1][i..j].max
end
n = 10001
l = []
100.times { l << adv(n); n += 2 }
loop \
{
$t = 0
l2 = l.map { |l1| f(l1) }
c = l2.size - l2.select { |x| x == 0 }.size
break if (c == 0)
puts([$t, c].join("\t"))
j = (0...l2.size).max_by { |x| l2[x] }
l[j][0] += 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment