[Tutor] exercise is recursion (more problems with my comp)

Timothy Wilson wilson@visi.com
Tue, 21 Nov 2000 07:11:47 -0600 (CST)


On Tue, 21 Nov 2000, Glen Wheeler wrote:

>   Well while looking at your code I thought I'd run it on my comp.  When I
> run this particular code on my computer if I enter any number bigger than 1
> the interpreter stops responding, but I can still use anything else (such as
> other applications).  Is this the error your talking about?

I realized later that the subject line is supposed to be "exercise *in*
recursion." How embarrassing. I also should have included some sample
output. Here's what I get:

wilsont@galileo:~/python$ python primefactor.py
Factor what number into primes? 100
number  i       factors
100     2       []
25      5       []
10      5       [2]
50      8       [2, 5]
25      5       [2, 5, 2]
20      5       [2, 5, 2, 4]
100     10      [2, 5, 2, 4, 5]

Notice the '4' in the list of prime factors. The program works correctly
sometimes, however:

wilsont@galileo:~/python$ python primefactor.py
Factor what number into primes? 12
number  i       factors
12      2       []
3       2       []
6       3       [2]
4       3       [2, 2]
12      4       [2, 2, 3]

It's been a very long time since I wrote a program that used recursion
(Hmmm...college...Pascal). I'd forgotten what a pain in the butt it is to
debug. Any hints?

-Tim

--
Tim Wilson      | Visit Sibley online:         | Check out:
Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/
W. St. Paul, MN |                              | http://slashdot.org/
wilson@visi.com |   <dtml-var pithy_quote>     | http://linux.com/