From b8ea525b41a698bc2c514f01e46420e592248411 Mon Sep 17 00:00:00 2001 From: Muhammad Nauman Raza Date: Wed, 20 Nov 2024 22:56:04 +0000 Subject: [PATCH] solutions: 16 --- power_digit_sum/Cargo.lock | 44 +++++++++++++++++++++++++++++++++++++ power_digit_sum/Cargo.toml | 7 ++++++ power_digit_sum/src/main.rs | 15 +++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 power_digit_sum/Cargo.lock create mode 100644 power_digit_sum/Cargo.toml create mode 100644 power_digit_sum/src/main.rs diff --git a/power_digit_sum/Cargo.lock b/power_digit_sum/Cargo.lock new file mode 100644 index 0000000..e8f9f19 --- /dev/null +++ b/power_digit_sum/Cargo.lock @@ -0,0 +1,44 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "power_digit_sum" +version = "0.1.0" +dependencies = [ + "num-bigint", +] diff --git a/power_digit_sum/Cargo.toml b/power_digit_sum/Cargo.toml new file mode 100644 index 0000000..86880a2 --- /dev/null +++ b/power_digit_sum/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "power_digit_sum" +version = "0.1.0" +edition = "2021" + +[dependencies] +num-bigint = "0.4.6" diff --git a/power_digit_sum/src/main.rs b/power_digit_sum/src/main.rs new file mode 100644 index 0000000..60e4620 --- /dev/null +++ b/power_digit_sum/src/main.rs @@ -0,0 +1,15 @@ +use num_bigint::BigUint; + +fn main() { + let mut number: BigUint = BigUint::from(2 as u32); + number = number.pow(1000); + + let number_list: Vec = number + .to_string() + .chars() + .filter_map(|c| c.to_digit(10).map(|d| d as u32)) + .collect(); + let sum: u32 = number_list.iter().sum(); + + println!("{}", sum); +}