title: Uva The 3n + 1 Problem - Wrong Answer Python
body: <p>I'm trying to solve a question from <a href="https://onlinejudge.org/index.php?option=com_onlinejudge&amp;Itemid=8&amp;page=show_problem&amp;problem=36" rel="nofollow noreferrer">onlinejudge.org - The 3n + 1 Problem</a> using Python.</p>
  <p>in case the link doesn't load (that happens quite frequently), below is my summarized version of the question:</p>
  <p>Consider the following algorithm:</p>
  <ol>
  <li>input n</li>
  <li>print n</li>
  <li>if n = 1 then STOP</li>
  <li>if n is odd then n  &lt;-  3n + 1</li>
  <li>else n  &lt;- n/2</li>
  <li>GOTO 2</li>
  </ol>
  <p>Given the input 22, the following sequence of numbers will be printed
  22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1</p>
  <p>In the example above, the cycle length of 22 is 16.</p>
  <p>For any two numbers i and j you are to determine the maximum cycle length over all numbers between and including both i and j.</p>
  <p>Sample Input</p>
  <pre><code>1 10
  100 200
  201 210
  900 1000
  </code></pre>
  <p>Sample Output</p>
  <pre><code>1 10 20
  100 200 125
  201 210 89
  900 1000 174
  </code></pre>
  <p>And here's my code.</p>
  <pre class="lang-py prettyprint-override"><code>inputText = input().split()
  
  inputList=[]
  for index in range(0, len(inputText), 2):
      inputList.append([int(inputText[index]), int(inputText[index + 1])])
  
  def CycleLen(num):
      chainList = [num]
      while num &gt; 1:
          chainList.append(num//2 if num % 2 == 0 else 3*num + 1)
          num = chainList[-1]
      return len(chainList)
  
  for listSet in inputList:
      countList = []
      minRange = min(listSet[0], listSet[1])
      maxRange = max(listSet[0], listSet[1])
      for num in range(minRange, maxRange + 1):
          countList.append(CycleLen(num))
  
      countList.sort()
      print(listSet[0], listSet[1], countList[-1])
  </code></pre>
  <p>I'm aware of the memorization solution to make it more time efficient, but I planned to implement that only if the question rejected my answer for exceeding time limit. However, I'm straight up getting the wrong answer, and I have no idea why.</p>
  <p>I used uDebug to see if there are any mistakes, and searched for other's solution. The most confusing part is how the online judge submits its input - single line by line, or all the lines at once. Different sources claim different things.</p>
  <p>Please help. Thank you!</p>