From 533c13876f08249844a3cb4e027d97f48a55f649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Fri, 22 Mar 2019 15:47:19 +0100 Subject: [PATCH] ?? --- .envrc | 1 + .gitignore | 2 ++ Cargo.lock | 33 +++++++++++++++++++++++++++++++++ Cargo.toml | 8 ++++++++ shell.nix | 20 ++++++++++++++++++++ src/main.rs | 30 ++++++++++++++++++++++++++++++ 6 files changed, 94 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 shell.nix create mode 100644 src/main.rs diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..4a4726a --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use_nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f0e3bca --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..1898679 --- /dev/null +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..01eb5e2 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "per" +version = "0.1.0" +authors = ["Daniel Løvbrøtte Olsen "] +edition = "2018" + +[dependencies] +num-bigint = "0.2" \ No newline at end of file diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..b044b5c --- /dev/null +++ b/shell.nix @@ -0,0 +1,20 @@ +let + moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz); + nixpkgs = import { 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 + ]; + } diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e79de24 --- /dev/null +++ b/src/main.rs @@ -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 = string.chars().map(|x| x as u8 - 48).collect(); + numbers.into_iter().product::() +} \ No newline at end of file