added ability to specify starting number of digits for collatz search, and a quick and dirty test of a power of 2 algorithm.
This commit is contained in:
parent
054879c11d
commit
828aaaee0a
3 changed files with 29 additions and 3 deletions
|
@ -3,7 +3,9 @@
|
|||
import sys
|
||||
import collatz
|
||||
|
||||
usage='usage: collatzSearch [digits] outputs the lenght of the collatz sequence for every number less than 10^digits'
|
||||
usage='usage: collatzSearch [digits] ([startDigits]) outputs the lenght of the collatz sequence for every number less than 10^digits, starting with 10^startDidgits.'
|
||||
|
||||
nextNumber = 1
|
||||
|
||||
if len(sys.argv)<2:
|
||||
print(usage)
|
||||
|
@ -15,8 +17,13 @@ try:
|
|||
except:
|
||||
print(usage)
|
||||
sys.exit()
|
||||
if len(sys.argv)>=3:
|
||||
try:
|
||||
nextNumber = 10**int(sys.argv[2])
|
||||
except:
|
||||
print(usage)
|
||||
sys.exit()
|
||||
|
||||
nextNumber = 1
|
||||
maxNumber = 10**digits
|
||||
|
||||
while nextNumber<maxNumber:
|
||||
|
|
|
@ -15,7 +15,9 @@ try:
|
|||
except:
|
||||
print(usage)
|
||||
sys.exit()
|
||||
|
||||
seqLength = 0
|
||||
while number != 1:
|
||||
number = collatz.nextInSequence(number)
|
||||
seqLength += 1
|
||||
print(number)
|
||||
print('length of '+str(seqLength))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue