> These two sequences of positive integers are defined as:
>
> R ( 1 ) = 1 ; S ( 1 ) = 2
> R ( n ) = R ( n - 1 ) + S ( n - 1 ) , n > 1
>
> The sequence S(n) is further defined as the sequence of
> positive integers not present in R(n).
>
> Sequence R starts: 1, 3, 7, 12, 18, ...
> Sequence S starts: 2, 4, 5, 6, 8, ...
>
> Task
>
> Create two functions named ffr and ffs that when given n
> return R(n) or S(n) respectively. (Note that R(1) = 1 and S(1)
> = 2 to avoid off-by-one errors).
>
> No maximum value for n should be assumed.
>
> Calculate and show that the first ten values of R are: 1, 3,
> 7, 12, 18, 26, 35, 45, 56, and 69
>
> Calculate and show that the first 40 values of ffr plus the
> first 960 values of ffs include all the integers from 1 to
> 1000 exactly once.
Ruby:
$r = [nil,1,3]
$s = [nil,2,4]
def extend
if $r.size == $s.size
$r << $r.last + $s.last
else
$s << ($s.last + 1 .. $s.last+3).find{|n| not $r.include?(n)}
end
end
def ffr(n)
extend until $r[n]
$r[n]
end
def ffs(n)
extend until $s[n]
$s[n]
end
(1..10).map{|i| ffr(i)}
==>[1, 3, 7, 12, 18, 26, 35, 45, 56, 69]
((1..40).map{|i| ffr(i)} + (1..960).map{|i| ffs(i)}).sort ==
(1..1000).to_a
==>true
In Forth?
--
From the New York Times of October 11, 1991, ... we learn that ... researchers
at Boston University admitted that, "There is no question but that Dr. King
plagiarized in the dissertation." ... "Dr. Martin Luther King, Jr." [Michael
King] spent his last night on Earth having sexual intercourse with two women at
the motel and physically beating and abusing a third.
www.revilo-oliver.com/Kevin-Strom-personal/Beast_as_Saint.html