Last active
March 31, 2024 15:55
-
-
Save nanpuyue/e971b2c4929c4a0f919392c3dc2d8f5b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// date: 2020-01-10 | |
// update: 2024-03-31 | |
// license: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt | |
// author: nanpuyue <[email protected]> https://blog.nanpuyue.com | |
#![feature(coroutines)] | |
#![feature(coroutine_trait)] | |
use std::ops::{Coroutine, CoroutineState}; | |
use std::pin::Pin; | |
struct CoroutineIter<T: Coroutine + Unpin>(T); | |
impl<T: Coroutine + Unpin> Iterator for CoroutineIter<T> { | |
type Item = <T as Coroutine>::Yield; | |
fn next(&mut self) -> Option<Self::Item> { | |
match Pin::new(&mut self.0).resume(()) { | |
CoroutineState::Yielded(x) => Some(x), | |
_ => None, | |
} | |
} | |
} | |
fn prime_generator() -> impl Coroutine<Yield = u16, Return = ()> { | |
|| { | |
yield 2; | |
yield 3; | |
let mut n = 3u16; | |
let mut l = vec![n]; | |
while let Some(x) = n.checked_add(2) { | |
n = x; | |
let mut y = true; | |
for &i in &l { | |
let (q, r) = (n / i, n % i); | |
if i > q { | |
break; | |
} else if r == 0 { | |
y = false; | |
break; | |
} | |
} | |
if y { | |
l.push(n); | |
yield n; | |
} | |
} | |
} | |
} | |
fn sha2_constant(root: f64) -> u32 { | |
(root.fract() * (1u64 << 32) as f64) as u32 | |
} | |
fn main() { | |
for v in CoroutineIter(prime_generator()).take(8) { | |
print!("{:#010x}, ", sha2_constant((v as f64).sqrt())); | |
} | |
println!("\n"); | |
for (i, v) in CoroutineIter(prime_generator()).take(64).enumerate() { | |
print!("{:#010x}, ", sha2_constant((v as f64).cbrt())); | |
if i % 8 == 7 { | |
println!(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hey, is it possible to work with firefox's css thing to combine titlebar and menubar instead of hiding title bar all together?