![]() |
|
|
|||||||
![]() |
Python - recursive method not reaching base case |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: 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 "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter Robert Kern |
|
|
|
#3 |
|
Posts: n/a
|
so obvious! thank you for helping me there. i knew it was simple, i
just couldn't catch it. possibilitybox |
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |