From d7f2e29b83031cc74de01a42ad6c1c486269abfd Mon Sep 17 00:00:00 2001 From: Muhammad Nauman Raza Date: Tue, 3 Dec 2024 09:46:00 +0000 Subject: [PATCH] solutions: 56 --- src/bin/powerful_digit_sum.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/bin/powerful_digit_sum.rs diff --git a/src/bin/powerful_digit_sum.rs b/src/bin/powerful_digit_sum.rs new file mode 100644 index 0000000..b6e7522 --- /dev/null +++ b/src/bin/powerful_digit_sum.rs @@ -0,0 +1,14 @@ +use num_bigint::BigUint; + +fn main() { + let mut sums: Vec = vec![]; + + for i in 1..100 { + for j in 1..100 { + let power = format!("{}", BigUint::from(i as u64).pow(j)); + sums.push(power.chars().filter_map(|c| c.to_digit(10)).sum()); + } + } + + println!("{}", sums.iter().max().unwrap()); +}