Skip to content

Instantly share code, notes, and snippets.

@adampalay
Created August 21, 2017 21:24
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 adampalay/e694068b38c0dbb36cdf8736e95a28a9 to your computer and use it in GitHub Desktop.
Save adampalay/e694068b38c0dbb36cdf8736e95a28a9 to your computer and use it in GitHub Desktop.
538 Number Sequence
from __future__ import division, print_function
def ratio(length):
number_concurrent_3s = 0
the_two_we_are_before = 1
threes_that_should_be_before_this_two = {1: 3}
number_3s = 0
number_2s = 0
for index in xrange(1, length + 1):
if number_concurrent_3s == threes_that_should_be_before_this_two[the_two_we_are_before]:
number_2s += 1
the_two_we_are_before += 1
threes_that_should_be_before_this_two[index] = 2
number_concurrent_3s = 0
else:
number_3s += 1
threes_that_should_be_before_this_two[index] = 3
number_concurrent_3s += 1
return number_3s / number_2s
if __name__ == '__main__':
print(ratio(1000000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment