Data update

This commit is contained in:
Ingy döt Net 2024-07-13 15:19:22 -07:00
parent 29a5eea0d4
commit 5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions

View file

@ -1,5 +1,5 @@
# sum power of digits
val .spod = fn(.n) fold fn{+}, map(fn(.x) .x^.x, s2n string .n)
val spod = fn n:fold(fn{+}, map(fn x:x^x, n -> string -> s2n))
# Munchausen
writeln "Answers: ", filter fn(.n) .n == .spod(.n), series 0..5000
writeln "Answers: ", filter(fn n: n == spod(n), series(1..5000))

View file

@ -0,0 +1,35 @@
use num_bigint::BigUint;
use num_traits::cast::ToPrimitive;
use rayon::prelude::*;
fn main() {
// Helper function to compute the Munchausen sum
fn munchausen_sum(num: &BigUint) -> BigUint {
num.to_string()
.chars()
.map(|c| {
let digit = c.to_digit(10).unwrap();
if digit == 0 {
BigUint::from(0u32)
} else {
BigUint::from(digit).pow(digit)
}
})
.sum::<BigUint>()
}
// Loop through the desired range
let start = BigUint::from(0u128);
let end = BigUint::from(1_000_00u128);
let solutions: Vec<BigUint> = (start.to_u128().unwrap()..end.to_u128().unwrap())
.into_par_iter()
.map(|n| BigUint::from(n))
.filter(|num| munchausen_sum(num) == *num)
.collect();
for solution in &solutions {
println!("Munchausen number found: {:?}", solution);
}
println!("Munchausen numbers below {:?}: {:?}", end, solutions);
}