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
$ time python -t -O problem14_nico.py | |
('The starting position generating the longest sequence is', 837799) | |
real 0m6.914s | |
user 0m6.645s | |
sys 0m0.202s | |
$ time python -t -O main_timer.py problem14 | |
args= ['main_timer.py', 'problem14'] | |
from problem14 import main |
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
""" | |
Longest Collatz sequence | |
------------------------ | |
The following iterative sequence is defined for the set of positive integers: | |
n n/2 (n is even) | |
n 3n + 1 (n is odd) | |
Using the rule above and starting with 13, we generate the following sequence: | |
13 40 20 10 5 16 8 4 2 1 | |
It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1. |
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
#! `env python` -t | |
def seq(n): | |
""" | |
Generate the sequence for Project Euler problem 14. | |
=================================================== | |
n is a positive integer that is the first number in the sequence. | |
I'm told that although it hasn't been proven, that it is believed that | |
regardless of the starting number, the sequence eventually gets to 1, |
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
#! `env python` -t | |
def seq(n): | |
""" | |
Generate the sequence for Project Euler problem 14. | |
=================================================== | |
n is a positive integer that is the first number in the sequence. | |
I'm told that although it hasn't been proven, that it is believed that | |
regardless of the starting number, the sequence eventually gets to 1, |
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 time import clock | |
if __name__ == "__main__": | |
import sys | |
print "args=", sys.argv | |
x="from " + sys.argv[1] + " import main" | |
print x | |
exec x | |
tstart=clock()*1000 | |
answer=main() | |
tend=clock()*1000 |