change library

This commit is contained in:
Daniel Løvbrøtte Olsen
2019-03-27 16:05:08 +01:00
parent d2c3fc8ef3
commit d62fd0f5eb
4 changed files with 163 additions and 19 deletions

View File

@@ -1,5 +1,6 @@
extern crate num_bigint;
// extern crate num_traits;
extern crate ramp;
use ramp::Int;
extern crate num_cpus;
#[macro_use]
extern crate clap;
@@ -8,13 +9,10 @@ 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};
@@ -23,17 +21,29 @@ trait Peristance {
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>();
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 {
fn per_mul(&self) -> u8 {
let mut n = self.to_str_radix(10, false)
.chars()
.map(|x| x - 48).collect()
.product::<Int>();
let mut counter = 1;
while n.to_str_radix(10).chars().count() > 1 {
n = n.to_radix_le(10)
.into_iter()
.product::<BigUint>();
while n.to_str_radix(10, false).chars().count() > 1 {
n = n.to_str_radix(10, false)
.chars()
.map(|x| x - 48).collect()
.product::<Int>();
counter += 1;
}
return counter;
@@ -43,21 +53,21 @@ impl Peristance for BigUint {
#[derive(Debug)]
struct Counter {
count: BigUint,
count: Int,
step: u8,
offset: u8
}
impl Counter {
fn new(_step: u8, _offset: u8) -> Counter {
Counter {count: BigUint::from(0u8), step: _step, offset: _offset}
Counter {count: Int::zero(), step: _step, offset: _offset}
}
}
impl Iterator for Counter {
type Item = BigUint;
type Item = Int;
fn next(&mut self) -> Option<BigUint> {
fn next(&mut self) -> Option<Int> {
// Increment our count. This is why we started at zero.
self.count += self.step;
Some(self.count.clone())