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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/// Returns the common difference between two terms of an arithmetic progression
///
/// # Arguments
///
/// * `term` - Any term of the AP
/// * `previous_term` - The term before `term`
///
/// # Examples
///
/// ```
/// use ariprog;
/// let common_diff = ariprog::common_difference(10.0, 5.0); // Should return 5
/// let cd = ariprog::common_difference(12.0, 2.0); // should return 10
/// ```
/// Returns the nth term of an arithmetic progression
///
/// # Arguments
///
/// * `first_term` - The first term of the AP
/// * `common_difference` - The common difference of the AP
/// * `nth_term_position` - The nth term position (nth) of the AP (e.g.: the twentieth term is in position 20)
///
/// # Examples
///
/// ```
/// use ariprog;
/// let nth_term = ariprog::nth_term(1.0, 2.0, 20.0); // Should return 39
/// ```
/// Returns the first term of an arithmetic progression
///
/// # Arguments
///
/// * `nth_term` - The nth term of the AP
/// * `common_difference` - The common difference of the AP
/// * `nth_term_position` - The nth term position (nth) of the AP (e.g.: the twentieth term is in position 20)
///
/// # Examples
///
/// ```
/// use ariprog;
/// let first_term = ariprog::first_term(-103.0, -2.0, 50.0); // Should return -5
/// ```
/// Returns an arithmetic progression with the first term + arithmetic means + nth_term, as a vector
///
/// # Arguments
///
/// * `how_many_in_between` - How many terms go between the first term and the nth term
/// * `first_term` - The first term of the AP
/// * `nth_term` - The nth term of the AP
///
/// # Examples
///
/// ```
/// use ariprog;
/// let ap = ariprog::insert_arithmetic_means(3, 1.0, 13.0); // Should return [1.0, 4.0, 7.0, 10.0, 13.0]
/// ```
/// Returns the number of terms in an AP
///
/// # Arguments
///
/// * `first_term` - The first term of the AP
/// * `nth_term` - The nth term of the AP
/// * `common_difference` - The common difference of the AP
///
/// # Examples
///
/// ```
/// use ariprog;
/// let n_of_terms = ariprog::how_many_terms(0.0, 100.0, 2.0); // Should return 51
/// ```
/// Returns the common difference and the first term, as a tuple (common_difference, first_term)
///
/// # Arguments
///
/// * `nth_term` - The nth term of the AP
/// * `term` - A term before the nth term
///
/// # Examples
///
/// ```
/// use ariprog;
/// let common_diff_and_first_term = ariprog::common_difference_and_first_term(
/// ariprog::NthTerm { value: 64.0, position: 8.0 },
/// ariprog::NthTerm { value: 32.0, position: 4.0 }
/// ); // Should return (8.0, 8.0)
/// ```