2021-02-08 18:29:13 +01:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import collatz
|
|
|
|
|
|
|
|
usage='usage: collatzSequence [number] prints the collatz sequence for the given number'
|
|
|
|
|
|
|
|
if len(sys.argv)<2:
|
|
|
|
Print(usage)
|
|
|
|
sys.exit()
|
|
|
|
number = sys.argv[1]
|
|
|
|
|
|
|
|
try:
|
|
|
|
number = int(number)
|
|
|
|
except:
|
|
|
|
print(usage)
|
|
|
|
sys.exit()
|
2021-02-20 23:57:18 +01:00
|
|
|
seqLength = 0
|
2021-02-08 18:29:13 +01:00
|
|
|
while number != 1:
|
|
|
|
number = collatz.nextInSequence(number)
|
2021-02-20 23:57:18 +01:00
|
|
|
seqLength += 1
|
2021-02-08 18:29:13 +01:00
|
|
|
print(number)
|
2021-02-20 23:57:18 +01:00
|
|
|
print('length of '+str(seqLength))
|