learningpython/collatz/collatzSearch.py

32 lines
673 B
Python
Raw Normal View History

2021-02-08 18:29:13 +01:00
#! /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
2021-02-08 18:29:13 +01:00
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()
2021-02-08 18:29:13 +01:00
maxNumber = 10**digits
while nextNumber<maxNumber:
print('collatz length of '+str(nextNumber)+' is: \n'+str(collatz.seqenceLength(nextNumber)))
nextNumber += 1