title: Hofstadter equation related code in python
body: <p>There was this question in a university assignment related to Hofstadter sequence. It basically say that it is a integer sequence blah blah and there are two values for a given index n. A male value [M(n)] and a female value [F(n)]. </p>
  
  <p>They are defined as:</p>
  
  <ul>
  <li>M(0)=0</li>
  <li>F(0)=1</li>
  <li>M(n)=n-F(M(n-1))</li>
  <li>F(n)=n-M(F(n-1))</li>
  </ul>
  
  <p>And we were asked to write a program in python to find the Male and Female values of the sequence of a given integer. </p>
  
  <p>So the code I wrote was:</p>
  
  <pre><code>def female(num):
      if num == 0:
          return 1
      elif num &gt;0:
          return num - male(female(num-1))
  def male(num):
      if num==0:
          return 0
      elif num &gt;0:
          return num - female(male(num-1))
  </code></pre>
  
  <p>And when executed with a command like 
    <code>print male(5)</code><br>
  It works without a fuss. But when I try to find the value of n = 300, the program gives no output. 
  So I added a print method inside one of the functions to find out what happens to the num value</p>
  
  <p>[     <code>elif num&gt;0:
              print num ...</code>]</p>
  
  <p>And it shows that the num value is decreasing until 1 and keeps hopping between 1 and 2 at times reaching values like 6. </p>
  
  <p>I can’t figure out why it happens. Any insight would be nice. Also what should I do to find the values relevant to bigger integers. Thanks in advance. Cheers. </p>