Go Back   Velocity Reviews > Newsgroups > Python
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Python - recursive method not reaching base case

 
Thread Tools Search this Thread
Old 03-24-2005, 01:51 AM   #1
Default recursive method not reaching base case


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



possibilitybox
  Reply With Quote
Old 03-24-2005, 02:20 AM   #2
Robert Kern
 
Posts: n/a
Default Re: recursive method not reaching base case
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


"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter


Robert Kern
  Reply With Quote
Old 03-24-2005, 02:28 AM   #3
possibilitybox
 
Posts: n/a
Default Re: recursive method not reaching base case
so obvious! thank you for helping me there. i knew it was simple, i
just couldn't catch it.



possibilitybox
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cooler Master Gladiator 600 Case Admin Front Page News 0 07-10-2009 10:52 AM
ThermalTake DH 102 Home Theater Case Admin Front Page News 0 06-12-2009 08:22 AM
Cancelling Timer and TimerTask threads wfalby Software 1 04-30-2009 01:04 PM
Lian Li Tyr PC-X500 Case Review Admin Front Page News 0 07-11-2008 09:02 PM
Judge: File-swapping tools are legal Citizen Bob DVD Video 140 11-08-2006 06:42 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46