Revert "add Change library"
This commit is contained in:
53
src/main.rs
53
src/main.rs
@@ -1,6 +1,5 @@
|
||||
extern crate ramp;
|
||||
use ramp::Int;
|
||||
|
||||
extern crate num_bigint;
|
||||
// extern crate num_traits;
|
||||
extern crate num_cpus;
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
@@ -9,32 +8,32 @@ extern crate clap;
|
||||
|
||||
use clap::App;
|
||||
|
||||
use num_bigint::BigUint;
|
||||
|
||||
use std::thread;
|
||||
// use std::sync::mpsc;
|
||||
use std::sync::{Arc, Barrier, RwLock};
|
||||
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
|
||||
|
||||
trait Peristance {
|
||||
fn per_mul(&self) -> i32;
|
||||
fn per_mul(&self) -> u8;
|
||||
}
|
||||
|
||||
impl Peristance for BigUint {
|
||||
fn per_mul(&self) -> u8 {
|
||||
let mut n = self.to_radix_le(10)
|
||||
.into_iter()
|
||||
.product::<BigUint>();
|
||||
|
||||
impl Peristance for Int {
|
||||
fn per_mul(&self) -> i32 {
|
||||
let mut n = self.to_str_radix(10, false)
|
||||
.chars()
|
||||
.map(|x| x as i32 - 48)
|
||||
.fold(Int::one(), |acc, x| acc * x);
|
||||
|
||||
let mut counter = 1;
|
||||
while n.to_str_radix(10, false).chars().count() > 1 {
|
||||
n = n.to_str_radix(10, false)
|
||||
.chars()
|
||||
.map(|x| x as i32 - 48)
|
||||
.fold(Int::one(), |acc, x| acc * x);
|
||||
while n.to_str_radix(10).chars().count() > 1 {
|
||||
n = n.to_radix_le(10)
|
||||
.into_iter()
|
||||
.product::<BigUint>();
|
||||
counter += 1;
|
||||
}
|
||||
return counter;
|
||||
@@ -44,21 +43,21 @@ impl Peristance for Int {
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Counter {
|
||||
count: Int,
|
||||
step: i32,
|
||||
offset: i32
|
||||
count: BigUint,
|
||||
step: u8,
|
||||
offset: u8
|
||||
}
|
||||
|
||||
impl Counter {
|
||||
fn new(_step: i32, _offset: i32) -> Counter {
|
||||
Counter {count: Int::zero(), step: _step, offset: _offset}
|
||||
fn new(_step: u8, _offset: u8) -> Counter {
|
||||
Counter {count: BigUint::from(0u8), step: _step, offset: _offset}
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for Counter {
|
||||
type Item = Int;
|
||||
type Item = BigUint;
|
||||
|
||||
fn next(&mut self) -> Option<Int> {
|
||||
fn next(&mut self) -> Option<BigUint> {
|
||||
// Increment our count. This is why we started at zero.
|
||||
self.count += self.step;
|
||||
Some(self.count.clone())
|
||||
@@ -78,13 +77,13 @@ fn main() {
|
||||
.get_matches();
|
||||
|
||||
|
||||
let mut cpus = value_t!(args, "jobs", i32).unwrap_or(num_cpus::get() as i32);
|
||||
let mut cpus = value_t!(args, "jobs", u8).unwrap_or(num_cpus::get() as u8);
|
||||
if cpus == 0 {
|
||||
cpus = num_cpus::get() as i32;
|
||||
cpus = num_cpus::get() as u8;
|
||||
}
|
||||
let cpus = cpus;
|
||||
|
||||
let max: i32 = value_t!(args, "max", i32).unwrap_or(11i32);
|
||||
let max = value_t!(args, "max", u8).unwrap_or(11u8);
|
||||
|
||||
println!("threads: {}", cpus);
|
||||
|
||||
@@ -94,7 +93,7 @@ fn main() {
|
||||
thread::spawn(move || {
|
||||
println!("Started thread {}!", thread);
|
||||
let counter = Counter::new(cpus-thread, cpus);
|
||||
let mut top: i32 = 0;
|
||||
let mut top: u8 = 0;
|
||||
for x in counter {
|
||||
let n = x.per_mul();
|
||||
if n > top {
|
||||
|
||||
Reference in New Issue
Block a user