Sha256: f612ccd4dac4775134a8bce8368da5c051ce853eda8689c4e5c973d866fb80e0
Contents?: true
Size: 1.48 KB
Versions: 5
Compression:
Stored size: 1.48 KB
Contents
# frozen_string_literal: true module ActiveRecall class FibonacciSequence def self.right(box:, times_right:, times_wrong:, current_time: Time.current) new( box: box, current_time: current_time, times_right: times_right, times_wrong: times_wrong ).right end def self.wrong(box:, times_right:, times_wrong:, current_time: Time.current) new( box: box, current_time: current_time, times_right: times_right, times_wrong: times_wrong ).wrong end def initialize(box:, times_right:, times_wrong:, current_time: Time.current) @box = box @current_time = current_time @times_right = times_right @times_wrong = times_wrong end def right { box: box + 1, last_reviewed: current_time, next_review: next_review, times_right: times_right + 1, times_wrong: times_wrong } end def wrong { box: [0, box - 1].max, last_reviewed: current_time, next_review: nil, times_right: times_right, times_wrong: times_wrong + 1 } end private attr_reader :box, :current_time, :times_right, :times_wrong def fibonacci_number_at(index) if (0..1).cover?(index) index else fibonacci_number_at(index - 1) + fibonacci_number_at(index - 2) end end def next_review current_time + fibonacci_number_at(box + 1).days end end end
Version data entries
5 entries across 5 versions & 1 rubygems