Sha256: 501e0dd493051ac9d5cc0426469fbb607f7d782380685e0869e41eadfe5493ed
Contents?: true
Size: 1.6 KB
Versions: 3
Compression:
Stored size: 1.6 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, 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 SEQUENCE = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765].freeze def fibonacci_number_at(index) if (0...SEQUENCE.length).cover?(index) SEQUENCE[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
3 entries across 3 versions & 1 rubygems