P
Peter Marsh
I'm sure everyone is fimilar with ranges:
(1..10).to_a = [1,2,3,4,5,6,7,8,9,10] (from manual)
But this isn't any good if you want a arithmetic [3,5,7,9] or geometric
[2,6,18,54] series. So I suggest this:
arithmetic_series = Arith.new(First_Term,Common_Difference)
aritmetic_series[9] will then generate the 10th term of the sequence (0
being the first to be consistent) and arithmetic_series[0..9] will
return an array with the first to tenth terms. The same goes for a
geometric series.
gemometric_series = Geometric.new(First_Term,Common_Ratio)
Now, there may be other ways to achieve this, but I think this way is
nicer.
(1..10).to_a = [1,2,3,4,5,6,7,8,9,10] (from manual)
But this isn't any good if you want a arithmetic [3,5,7,9] or geometric
[2,6,18,54] series. So I suggest this:
arithmetic_series = Arith.new(First_Term,Common_Difference)
aritmetic_series[9] will then generate the 10th term of the sequence (0
being the first to be consistent) and arithmetic_series[0..9] will
return an array with the first to tenth terms. The same goes for a
geometric series.
gemometric_series = Geometric.new(First_Term,Common_Ratio)
Now, there may be other ways to achieve this, but I think this way is
nicer.