Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
30
third-party/vendor/generator/examples/number.rs
vendored
Normal file
30
third-party/vendor/generator/examples/number.rs
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
use generator::*;
|
||||
|
||||
fn factors(n: u32) -> Generator<'static, (), u32> {
|
||||
Gn::new_scoped(move |mut s| {
|
||||
if n == 0 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
s.yield_with(1);
|
||||
|
||||
for i in 2..n {
|
||||
if n % i == 0 {
|
||||
s.yield_with(i);
|
||||
}
|
||||
}
|
||||
done!();
|
||||
})
|
||||
}
|
||||
|
||||
fn main() {
|
||||
for i in factors(28) {
|
||||
println!("{i}");
|
||||
}
|
||||
|
||||
(0..10000)
|
||||
.filter(|n| factors(*n).sum::<u32>() == *n)
|
||||
.fold((), |_, n| {
|
||||
println!("n = {n}");
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue