File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed
Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 253253 * [ Sum Of Harmonic Series] ( https://github.com/TheAlgorithms/Rust/blob/master/src/math/sum_of_harmonic_series.rs )
254254 * [ Sylvester Sequence] ( https://github.com/TheAlgorithms/Rust/blob/master/src/math/sylvester_sequence.rs )
255255 * [ Tanh] ( https://github.com/TheAlgorithms/Rust/blob/master/src/math/tanh.rs )
256+ * [ Tetrahedral Number] ( https://github.com/TheAlgorithms/Rust/blob/master/src/math/tetrahedral_number.rs )
256257 * [ Trapezoidal Integration] ( https://github.com/TheAlgorithms/Rust/blob/master/src/math/trapezoidal_integration.rs )
257258 * [ Trial Division] ( https://github.com/TheAlgorithms/Rust/blob/master/src/math/trial_division.rs )
258259 * [ Trig Functions] ( https://github.com/TheAlgorithms/Rust/blob/master/src/math/trig_functions.rs )
Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ mod sum_of_geometric_progression;
7676mod sum_of_harmonic_series;
7777mod sylvester_sequence;
7878mod tanh;
79+ mod tetrahedral_number;
7980mod trapezoidal_integration;
8081mod trial_division;
8182mod trig_functions;
@@ -168,6 +169,7 @@ pub use self::sum_of_geometric_progression::sum_of_geometric_progression;
168169pub use self :: sum_of_harmonic_series:: sum_of_harmonic_progression;
169170pub use self :: sylvester_sequence:: sylvester;
170171pub use self :: tanh:: tanh;
172+ pub use self :: tetrahedral_number:: tetrahedral_number;
171173pub use self :: trapezoidal_integration:: trapezoidal_integral;
172174pub use self :: trial_division:: trial_division;
173175pub use self :: trig_functions:: cosine;
Original file line number Diff line number Diff line change 1+ // Tetrahedral Numbers: Function to the Nth Tetrahedral Number
2+ // Wikipedia Reference : https://en.wikipedia.org/wiki/Tetrahedral_number
3+ use num_bigint:: BigUint ;
4+ pub fn tetrahedral_number ( n : u64 ) -> BigUint {
5+ let m: BigUint = ( ( ( n) * ( n + 1 ) * ( n + 2 ) ) / 6 ) . into ( ) ;
6+ m
7+ }
8+
9+ #[ cfg( test) ]
10+ mod tests {
11+ use super :: * ;
12+
13+ macro_rules! test_tetrahedral_number {
14+ ( $( $name: ident: $inputs: expr, ) * ) => {
15+ $(
16+ #[ test]
17+ fn $name( ) {
18+ let ( n, expected) =$inputs;
19+ assert_eq!( tetrahedral_number( n) , expected) ;
20+ }
21+ ) *
22+ }
23+ }
24+
25+ test_tetrahedral_number ! {
26+ input_6: ( 6 , BigUint :: from( 56u32 ) ) ,
27+ input_8: ( 8 , BigUint :: from( 120u32 ) ) ,
28+ input_34: ( 34 , BigUint :: from( 7140u32 ) ) ,
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments