From 828aaaee0a2f1e9101f38c97be2b50c76d769405 Mon Sep 17 00:00:00 2001 From: gabriel venberg Date: Sat, 20 Feb 2021 16:57:18 -0600 Subject: [PATCH] added ability to specify starting number of digits for collatz search, and a quick and dirty test of a power of 2 algorithm. --- collatz/collatzSearch.py | 11 +++++++++-- collatz/collatzSequence.py | 4 +++- powerOf2.py | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100755 powerOf2.py diff --git a/collatz/collatzSearch.py b/collatz/collatzSearch.py index 0a0c9b0..de9b8c3 100755 --- a/collatz/collatzSearch.py +++ b/collatz/collatzSearch.py @@ -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