By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,660 Members | 1,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,660 IT Pros & Developers. It's quick & easy.

recursive method not reaching base case

P: n/a
i was working on implementing the original supermemo algorithm (see
http://www.supermemo.com/english/ol/sm2.htm for a description of it) in
a class, and i'd just finished up the first draft. it works for
repetitions one and two, but on repetition three (you must manually
increment item.reps.) or higher it recurses until it reaches the limit.
can someone point out what i'm doing wrong here?

here's the code:
class item:
def __init__(self, key, value):
self.key = key
self.value = value
self.reps = 1
self.ef = 2.5
def interval(self):
if(self.reps==1):
return 2
if(self.reps==2):
return 6
return (self.interval() - 1) * self.ef

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
possibilitybox wrote:
i was working on implementing the original supermemo algorithm (see
http://www.supermemo.com/english/ol/sm2.htm for a description of it) in
a class, and i'd just finished up the first draft. it works for
repetitions one and two, but on repetition three (you must manually
increment item.reps.) or higher it recurses until it reaches the limit.
can someone point out what i'm doing wrong here?

here's the code:
class item:
def __init__(self, key, value):
self.key = key
self.value = value
self.reps = 1
self.ef = 2.5
def interval(self):
if(self.reps==1):
return 2
if(self.reps==2):
return 6
return (self.interval() - 1) * self.ef


You're not changing self.reps at all, so interval() keeps getting called
over and over again with self.reps == 3.

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
Jul 18 '05 #2

P: n/a
so obvious! thank you for helping me there. i knew it was simple, i
just couldn't catch it.

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.