Posted By

bretsky on 02/10/14


Tagged


Versions (?)

Collatz conjecture tester (only prints results)


 / Published in: Python
 

Try it out in a python interpreter!

  1. def mathprob_no_print(x):
  2. string2 = str(x)
  3. while x != 1:
  4. if x % 2 == 0:
  5. x = x/2
  6. else:
  7. x = 3 * x + 1
  8. if x == 1:
  9. return string2+" was a failure"
  10. else:
  11. return string2+" passed the test!"
  12.  
  13.  
  14.  
  15. def math_repeat(x,p):
  16. while x <= p:
  17. print mathprob_no_print(x)
  18. x = x + 1
  19.  
  20. math_repeat(1,100)

Report this snippet  

You need to login to post a comment.