-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepeat.rb
More file actions
48 lines (40 loc) · 846 Bytes
/
repeat.rb
File metadata and controls
48 lines (40 loc) · 846 Bytes
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
47
48
require 'pp'
INITIAL_EASE_FACTOR = 2.5 # ease factor for initial items
VEASY = 5
EASY = 4
MEDIUM = 3
HARD = 2
VHARD = 1
ONE_DAY = 1
SIX_DAYS = 6
module Repetitions
def self.next_rep(iteration, last_interval, ease_factor)
case iteration
when 1
return ONE_DAY
when 6
return SIX_DAYS
else
return last_interval*ease_factor
end
end
end
module EaseFactor
# Magic numbers, anyway to clarify the significance of the numbers in this formula?
def self.update_function(q, ef)
ef - 0.8 + 0.28 * q - 0.02 * q * q
end
end
class Card
def initialize()
@ef = INITIAL_EASE_FACTOR
@reps = 0
@next_rep = 0
end
def review(score)
@reps += 1
@ef = EaseFactor.update_function(score, @ef)
@next_rep = Repetitions.next_rep(@reps, @next_rep, @ef)
@next_rep
end
end