init
This commit is contained in:
6
problems/p12/Cargo.toml
Normal file
6
problems/p12/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "p12"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
42
problems/p12/src/main.rs
Normal file
42
problems/p12/src/main.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
struct TriNum {
|
||||
current: usize,
|
||||
sum: usize,
|
||||
}
|
||||
|
||||
impl TriNum {
|
||||
fn new() -> Self {
|
||||
Self { current: 0, sum: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for TriNum {
|
||||
type Item = usize;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.current += 1;
|
||||
self.sum += self.current;
|
||||
Some(self.sum)
|
||||
}
|
||||
}
|
||||
|
||||
fn factor_count(input: usize) -> usize {
|
||||
let max = (input as f32).sqrt() as usize;
|
||||
let mut count = 0;
|
||||
for i in 1..=max {
|
||||
if input % i == 0 {
|
||||
count += 2;
|
||||
}
|
||||
}
|
||||
count
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let tri_num = TriNum::new();
|
||||
for i in tri_num {
|
||||
let count = factor_count(i);
|
||||
if count > 500 {
|
||||
println!("i: {i}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user