add Change library
This commit is contained in:
parent
d62fd0f5eb
commit
778668a7b9
37
src/main.rs
37
src/main.rs
|
@ -18,32 +18,23 @@ use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
|
||||||
trait Peristance {
|
trait Peristance {
|
||||||
fn per_mul(&self) -> u8;
|
fn per_mul(&self) -> i32;
|
||||||
}
|
|
||||||
|
|
||||||
trait MyProduct<A = Self> {
|
|
||||||
fn product<I: Iterator<Item=A>>(iter: I) -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MyProduct<Int> for Int {
|
|
||||||
fn product<I: Iterator<Item=Self>>(iter: I) -> Int {
|
|
||||||
iter.fold(Int::one(), <ramp::Int as Trait>::Mul)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Peristance for Int {
|
impl Peristance for Int {
|
||||||
fn per_mul(&self) -> u8 {
|
fn per_mul(&self) -> i32 {
|
||||||
let mut n = self.to_str_radix(10, false)
|
let mut n = self.to_str_radix(10, false)
|
||||||
.chars()
|
.chars()
|
||||||
.map(|x| x - 48).collect()
|
.map(|x| x as i32 - 48)
|
||||||
.product::<Int>();
|
.fold(Int::one(), |acc, x| acc * x);
|
||||||
|
|
||||||
let mut counter = 1;
|
let mut counter = 1;
|
||||||
while n.to_str_radix(10, false).chars().count() > 1 {
|
while n.to_str_radix(10, false).chars().count() > 1 {
|
||||||
n = n.to_str_radix(10, false)
|
n = n.to_str_radix(10, false)
|
||||||
.chars()
|
.chars()
|
||||||
.map(|x| x - 48).collect()
|
.map(|x| x as i32 - 48)
|
||||||
.product::<Int>();
|
.fold(Int::one(), |acc, x| acc * x);
|
||||||
counter += 1;
|
counter += 1;
|
||||||
}
|
}
|
||||||
return counter;
|
return counter;
|
||||||
|
@ -54,12 +45,12 @@ impl Peristance for Int {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Counter {
|
struct Counter {
|
||||||
count: Int,
|
count: Int,
|
||||||
step: u8,
|
step: i32,
|
||||||
offset: u8
|
offset: i32
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Counter {
|
impl Counter {
|
||||||
fn new(_step: u8, _offset: u8) -> Counter {
|
fn new(_step: i32, _offset: i32) -> Counter {
|
||||||
Counter {count: Int::zero(), step: _step, offset: _offset}
|
Counter {count: Int::zero(), step: _step, offset: _offset}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,13 +78,13 @@ fn main() {
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
|
|
||||||
let mut cpus = value_t!(args, "jobs", u8).unwrap_or(num_cpus::get() as u8);
|
let mut cpus = value_t!(args, "jobs", i32).unwrap_or(num_cpus::get() as i32);
|
||||||
if cpus == 0 {
|
if cpus == 0 {
|
||||||
cpus = num_cpus::get() as u8;
|
cpus = num_cpus::get() as i32;
|
||||||
}
|
}
|
||||||
let cpus = cpus;
|
let cpus = cpus;
|
||||||
|
|
||||||
let max = value_t!(args, "max", u8).unwrap_or(11u8);
|
let max: i32 = value_t!(args, "max", i32).unwrap_or(11i32);
|
||||||
|
|
||||||
println!("threads: {}", cpus);
|
println!("threads: {}", cpus);
|
||||||
|
|
||||||
|
@ -103,7 +94,7 @@ fn main() {
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
println!("Started thread {}!", thread);
|
println!("Started thread {}!", thread);
|
||||||
let counter = Counter::new(cpus-thread, cpus);
|
let counter = Counter::new(cpus-thread, cpus);
|
||||||
let mut top: u8 = 0;
|
let mut top: i32 = 0;
|
||||||
for x in counter {
|
for x in counter {
|
||||||
let n = x.per_mul();
|
let n = x.per_mul();
|
||||||
if n > top {
|
if n > top {
|
||||||
|
|
Loading…
Reference in New Issue