Skip to content

Commit 032de85

Browse files
author
WinterPancake
committed
Added comments explaining what the module provides. Removed BigUint for being overkill. Removed the use and returning of the variable m. Renamed the names of the test cases to something more logical.
1 parent 9a57953 commit 032de85

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/math/tetrahedral_number.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// Tetrahedral Numbers: Function to the Nth Tetrahedral Number
22
// 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
3+
//
4+
// This program provides a function to calculate the nth triangular
5+
// number defined by T_n = 1 + 2 + ... + n = (n(n + 1)(n + 2))/6 =
6+
// (n + 2) choose 3.
7+
8+
pub fn tetrahedral_number(n: u64) -> u64 {
9+
((n) * (n + 1) * (n + 2)) / 6
710
}
811

912
#[cfg(test)]
@@ -23,8 +26,11 @@ mod tests {
2326
}
2427

2528
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+
input_0: (0, 0),
30+
input_1: (1, 1),
31+
input_2: (6, 56),
32+
input_3: (8, 120),
33+
input_4: (11, 286),
34+
input_5: (34, 7140),
2935
}
3036
}

0 commit comments

Comments
 (0)