Created
August 21, 2017 21:24
-
-
Save adampalay/e694068b38c0dbb36cdf8736e95a28a9 to your computer and use it in GitHub Desktop.
538 Number Sequence
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
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