32 lines
673 B
Python
Executable file
32 lines
673 B
Python
Executable file
#! /usr/bin/env python3
|
|
|
|
import sys
|
|
import collatz
|
|
|
|
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)
|
|
sys.exit()
|
|
digits = sys.argv[1]
|
|
|
|
try:
|
|
digits = int(digits)
|
|
except:
|
|
print(usage)
|
|
sys.exit()
|
|
if len(sys.argv)>=3:
|
|
try:
|
|
nextNumber = 10**int(sys.argv[2])
|
|
except:
|
|
print(usage)
|
|
sys.exit()
|
|
|
|
maxNumber = 10**digits
|
|
|
|
while nextNumber<maxNumber:
|
|
print('collatz length of '+str(nextNumber)+' is: \n'+str(collatz.seqenceLength(nextNumber)))
|
|
nextNumber += 1
|