Skip to content

Instantly share code, notes, and snippets.

View ggssh's full-sized avatar
:octocat:
Focusing

Yizhe Yuan ggssh

:octocat:
Focusing
  • Institute of Computing Technology, Chinese Academy of Sciences
  • Beijing, China
  • 09:03 (UTC +08:00)
View GitHub Profile
@ggssh
ggssh / sleep_sort.rs
Created September 14, 2024 08:10
Sleep Sort
fn sleep_sort(arr: &mut [u64]) {
let (s, r) = std::sync::mpsc::channel();
for &n in arr {
let s = s.clone();
std::thread::spawn(move || {
std::thread::sleep(std::time::Duration::from_millis(n));
s.send(n).unwrap();
});
}
*arr = r.iter().collect::<Vec<_>>();
@ggssh
ggssh / monkey_sort.rs
Created July 28, 2023 02:39
Monkey Sort
fn monkey_sort<T: Ord>(arr: &mut [T]) {
while !is_sorted(arr) {
arr.shuffle(&mut rand::thread_rng());
}
}