add 92
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "euler92"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[profile.release]
|
||||
lto = "fat"
|
||||
@@ -0,0 +1,38 @@
|
||||
const MAXIMUM: usize = 10_000_000;
|
||||
|
||||
fn main() {
|
||||
let mut arrives_at_89 = 0;
|
||||
|
||||
for i in 1..MAXIMUM {
|
||||
let mut number = i;
|
||||
loop {
|
||||
let sum: usize = number
|
||||
.to_digits()
|
||||
.into_iter()
|
||||
.map(|d| d.pow(2) as usize)
|
||||
.sum();
|
||||
if sum == 89 {
|
||||
arrives_at_89 += 1;
|
||||
break;
|
||||
} else if sum == 1 {
|
||||
break;
|
||||
}
|
||||
number = sum;
|
||||
}
|
||||
}
|
||||
|
||||
println!("{arrives_at_89}");
|
||||
}
|
||||
|
||||
trait ToDigits {
|
||||
fn to_digits(&self) -> Vec<u8>;
|
||||
}
|
||||
|
||||
impl ToDigits for usize {
|
||||
fn to_digits(&self) -> Vec<u8> {
|
||||
self.to_string()
|
||||
.chars()
|
||||
.map(|c| c.to_digit(10).unwrap() as _)
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user