Module: SuperMemo

Defined in:
lib/forgetful/supermemo.rb

Constant Summary collapse

D_EF =

D_EF = (0.1 - (5-q) * (0.08 + (5-q) * 0.02))

{ 0 => -0.8,
1 => -0.54,
2 => -0.32,
3 => -0.14,
4 =>  0,
5 =>  0.1 }

Class Method Summary collapse

Class Method Details

.next_date(date, qs) ⇒ Object



39
40
41
42
# File 'lib/forgetful/supermemo.rb', line 39

def self.next_date(date, qs)
  ef, i, interval = traverse(qs)
  date + interval
end

.next_ef(q, ef) ⇒ Object



10
11
12
# File 'lib/forgetful/supermemo.rb', line 10

def self.next_ef(q, ef)
  [ef + D_EF[q], 1.3].max
end

.next_i(q, i) ⇒ Object



14
15
16
17
18
# File 'lib/forgetful/supermemo.rb', line 14

def self.next_i(q, i)
  return 0 if q < 3

  i+1
end

.next_interval(q, ef, i, interval) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/forgetful/supermemo.rb', line 20

def self.next_interval(q, ef, i, interval)
  return 1 if q < 3

  case i
  when 0 then 1
  when 1 then 6
  else        (interval * ef).round
  end
end

.traverse(qs, ef = 2.5, i = 0, interval = 0) ⇒ Object

-> 2.5, 0, 0

5,5,5

-> 2.8, 3, 16



32
33
34
35
36
37
# File 'lib/forgetful/supermemo.rb', line 32

def self.traverse(qs, ef=2.5, i=0, interval=0)
  return [ef, i, interval] if qs.empty?

  q = qs.first
  traverse(qs[1..-1], next_ef(q, ef), next_i(q, i), next_interval(q, ef, i, interval))
end