Last active
June 3, 2020 09:46
-
-
Save gyng/0c856ac0cf7cdbd9660d to your computer and use it in GitHub Desktop.
my first fizzbuzz
This file contains 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
use std::io::stdio::flush; | |
use std::io::timer::sleep; | |
use std::thread::{Thread, JoinGuard}; | |
use std::time::duration::Duration; | |
fn main() { | |
let mut threads: Vec<JoinGuard<()>> = Vec::new(); | |
threads.push(Thread::spawn(|| { | |
let mut i = 0u; | |
loop { | |
i = i + 1; | |
print!("\n{}", i); | |
flush(); | |
sleep(Duration::seconds(1)); | |
} | |
})); | |
threads.push(Thread::spawn(|| { | |
loop { | |
print!("\rfizzbuzz"); | |
flush(); | |
sleep(Duration::seconds(15)); | |
} | |
})); | |
threads.push(Thread::spawn(|| { | |
loop { | |
print!("\rbuzz"); | |
flush(); | |
sleep(Duration::seconds(5)); | |
} | |
})); | |
threads.push(Thread::spawn(|| { | |
loop { | |
print!("\rfizz"); | |
flush(); | |
sleep(Duration::seconds(3)); | |
} | |
})); | |
for thread in threads.into_iter() { | |
let _ = thread.join(); | |
} | |
} |
This file contains 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
proff it works | |
8PS C:\Users\Cube\Desktop> cargo run | |
Compiling rust-raytracer v0.1.0 (file:C:\Users\Cube\Desktop) | |
Running `target\rust-raytracer` | |
fizzbuzz | |
1 | |
2 | |
fizz | |
4 | |
buzz | |
fizz | |
7 | |
8 | |
fizz | |
buzz | |
11 | |
fizz | |
13 | |
14 | |
fizzbuzz | |
16 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment