-
Notifications
You must be signed in to change notification settings - Fork 0
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
cc1c7ff
commit 539e620
Showing
10 changed files
with
302 additions
and
61 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
.PHONY: dev integrate test | ||
.PHONY: build-ramp dev integrate test | ||
|
||
build-ramp: | ||
cargo +nightly build --no-default-features --features backend-ramp | ||
|
||
dev: | ||
rustup component add rustfmt | ||
rustup toolchain install nightly | ||
|
||
integrate: | ||
./integrate/check | ||
|
||
test: | ||
cargo fmt -- --check | ||
cargo test --locked | ||
./test/check |
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,48 @@ | ||
extern crate num_bigint; | ||
extern crate num_traits; | ||
|
||
use num_bigint::BigUint; | ||
use num_traits::Num; | ||
|
||
lazy_static! { | ||
static ref BIG_UINT_NINE: BigUint = BigUint::from(9 as usize); | ||
} | ||
|
||
/// Multiply digits of an integer together and return the result. | ||
fn multiply_digits(a: &BigUint) -> BigUint { | ||
a.to_str_radix(10) | ||
.chars() | ||
.map(|c| BigUint::from(c.to_digit(10).expect("Could not convert char to digit."))) | ||
.product() | ||
} | ||
|
||
/// Return the multiplicative persistence of a positive integer given as a string. | ||
pub fn multiplicative_persistence(candidate: &str) -> usize { | ||
let mut derived_int: BigUint = | ||
Num::from_str_radix(candidate, 10).expect("Could not convert candidate to BigUint"); | ||
|
||
let mut counter: usize = 0; | ||
while derived_int > *BIG_UINT_NINE { | ||
derived_int = multiply_digits(&derived_int); | ||
counter += 1; | ||
} | ||
counter | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
/// Test helper to cut down on boilerplate | ||
fn big(n: usize) -> BigUint { | ||
BigUint::from(n) | ||
} | ||
|
||
#[test] | ||
fn test_multiply_digits() { | ||
assert_eq!(multiply_digits(&big(0)), big(0)); | ||
assert_eq!(multiply_digits(&big(3)), big(3)); | ||
assert_eq!(multiply_digits(&big(24)), big(8)); | ||
assert_eq!(multiply_digits(&big(12345)), big(120)); | ||
} | ||
} |
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,48 @@ | ||
extern crate ramp; | ||
|
||
use std::ops::Mul; | ||
|
||
use ramp::Int; | ||
|
||
lazy_static! { | ||
static ref RAMP_NINE: Int = Int::from(9); | ||
} | ||
|
||
/// Multiply digits of an integer together and return the result. | ||
fn multiply_digits(a: &Int) -> Int { | ||
a.to_str_radix(10, false) | ||
.chars() | ||
.map(|c| Int::from(c.to_digit(10).expect("Could not convert char to digit."))) | ||
.fold(Int::one(), Int::mul) | ||
} | ||
|
||
/// Return the multiplicative persistence of a positive integer given as a string. | ||
pub fn multiplicative_persistence(candidate: &str) -> usize { | ||
let mut derived_int = | ||
Int::from_str_radix(candidate, 10).expect("Could not convert candidate to BigUint"); | ||
|
||
let mut counter: usize = 0; | ||
while derived_int > *RAMP_NINE { | ||
derived_int = multiply_digits(&derived_int); | ||
counter += 1; | ||
} | ||
counter | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
/// Test helper to cut down on boilerplate | ||
fn big(n: usize) -> Int { | ||
Int::from(n) | ||
} | ||
|
||
#[test] | ||
fn test_multiply_digits() { | ||
assert_eq!(multiply_digits(&big(0)), big(0)); | ||
assert_eq!(multiply_digits(&big(3)), big(3)); | ||
assert_eq!(multiply_digits(&big(24)), big(8)); | ||
assert_eq!(multiply_digits(&big(12345)), big(120)); | ||
} | ||
} |
Oops, something went wrong.