This commit is contained in:
commit
533c13876f
|
@ -0,0 +1,2 @@
|
||||||
|
/target
|
||||||
|
**/*.rs.bk
|
|
@ -0,0 +1,33 @@
|
||||||
|
[[package]]
|
||||||
|
name = "num-bigint"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-integer"
|
||||||
|
version = "0.1.39"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "per"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"num-bigint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[metadata]
|
||||||
|
"checksum num-bigint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "57450397855d951f1a41305e54851b1a7b8f5d2e349543a02a2effe25459f718"
|
||||||
|
"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
|
||||||
|
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
|
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "per"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Daniel Løvbrøtte Olsen <daniel@dodsorf.as>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
num-bigint = "0.2"
|
|
@ -0,0 +1,20 @@
|
||||||
|
let
|
||||||
|
moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
|
||||||
|
nixpkgs = import <nixpkgs> { overlays = [ moz_overlay ]; };
|
||||||
|
rustNightlyChannel = (nixpkgs.rustChannelOf { date = "2019-01-26"; channel = "nightly"; }).rust;
|
||||||
|
rustStableChannel = nixpkgs.latest.rustChannels.stable.rust.override {
|
||||||
|
extensions = [
|
||||||
|
"rust-src"
|
||||||
|
"rls-preview"
|
||||||
|
"clippy-preview"
|
||||||
|
"rustfmt-preview"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
in
|
||||||
|
with nixpkgs;
|
||||||
|
stdenv.mkDerivation {
|
||||||
|
name = "moz_overlay_shell";
|
||||||
|
buildInputs = [
|
||||||
|
rustStableChannel
|
||||||
|
];
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
extern crate num_bigint;
|
||||||
|
// extern crate num_traits;
|
||||||
|
|
||||||
|
use num_bigint::BigUint;
|
||||||
|
|
||||||
|
|
||||||
|
fn main()
|
||||||
|
{
|
||||||
|
let mut num = BigUint::from(0 as u8);
|
||||||
|
num = num + 277777788888899u128;
|
||||||
|
|
||||||
|
println!("{:?}", test(num));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test(input: BigUint) -> u8 {
|
||||||
|
let mut n = factorize(input);
|
||||||
|
let mut counter = 1;
|
||||||
|
while (n.to_str_radix(10).chars().count() > 0) {
|
||||||
|
n = factorize(n);
|
||||||
|
println!("n: {:?}", n);
|
||||||
|
counter += 1;
|
||||||
|
}
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn factorize(input: BigUint) -> BigUint {
|
||||||
|
let string = input.to_str_radix(10);
|
||||||
|
let numbers: Vec<u8> = string.chars().map(|x| x as u8 - 48).collect();
|
||||||
|
numbers.into_iter().product::<BigUint>()
|
||||||
|
}
|
Loading…
Reference in New Issue