-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2009cd
commit 10394fa
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/// Compute the multiplication set of the three largest numbers in an array | ||
pub fn maximum(mut nums: Vec<i32>) -> i32 { | ||
nums.sort(); | ||
(nums[nums.len() - 1] * nums[nums.len() - 2] * nums[nums.len() - 3]) | ||
.max(nums[0] * nums[nums.len() - 1] * nums[nums.len() - 2]) | ||
.max(nums[0] * nums[1] * nums[nums.len() - 1]) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
macro_rules! test_maximum { | ||
($($name:ident: $inputs:expr,)*) => { | ||
$( | ||
#[test] | ||
fn $name() { | ||
let (s, expected) = $inputs; | ||
assert_eq!(maximum(s.to_vec()), expected); | ||
} | ||
)* | ||
} | ||
} | ||
|
||
test_maximum! { | ||
positive0: ([1,2,3], 6), | ||
positive1: ([1,2,3,4], 24), | ||
negative0: ([-1,-2,-3], -6), | ||
negative1: ([-1,-2,-3,-4,-5], -6), | ||
positive_and_negative0: ([-1,-2,-3,4,5], 30), | ||
positive_and_negative1: ([-1,2,-3,-4,5], 60), | ||
positive_and_negative2: ([-1,2,-3,4,5], 40), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
#![cfg(feature = "big-math")] | ||
|
||
mod fast_factorial; | ||
mod maximum; | ||
mod multiply; | ||
mod poly1305; | ||
|
||
pub use self::fast_factorial::fast_factorial; | ||
pub use self::maximum::maximum; | ||
pub use self::multiply::multiply; | ||
pub use self::poly1305::Poly1305; |