Last active
January 27, 2017 14:12
-
-
Save NoraCodes/2bed40527d3920a73e9054fc80876b9c to your computer and use it in GitHub Desktop.
A parallel FizzBuzz implementation with Rust. Requires Rayon ^0.6
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
| extern crate rayon; | |
| use rayon::prelude::*; | |
| fn fizzbuzz(i: i32) { | |
| match (i % 3 == 0, i % 5 == 0) { | |
| // Added showing instances where there is no valid divisor on /u/XANI_'s suggestion | |
| // I really like it, actually, because it lets you see how the parallel iterator has | |
| // chunked up the problem. Very cool. | |
| (false, false) => {println!("{} ", i); }, | |
| (true, true) => { println!("{}: FizzBuzz", i); }, | |
| (true, false) => { println!("{}: Fizz", i); }, | |
| (false, true) => { println!("{}: Buzz", i); } | |
| } | |
| } | |
| fn main() { | |
| (1..75).into_par_iter().for_each(|n| { fizzbuzz(n);}); | |
| } |
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
| 38 | |
| 39: Fizz | |
| 40: Buzz | |
| 41 | |
| 42: Fizz | |
| 43 | |
| 44 | |
| 45: FizzBuzz | |
| 46 | |
| 47 | |
| 48: Fizz | |
| 49 | |
| 50: Buzz | |
| 51: Fizz | |
| 52 | |
| 53 | |
| 54: Fizz | |
| 55: Buzz | |
| 65: Buzz | |
| 66: Fizz | |
| 67 | |
| 68 | |
| 69: Fizz | |
| 70: Buzz | |
| 71 | |
| 72: Fizz | |
| 73 | |
| 74 | |
| 19 | |
| 20: Buzz | |
| 21: Fizz | |
| 22 | |
| 23 | |
| 24: Fizz | |
| 25: Buzz | |
| 26 | |
| 27: Fizz | |
| 28 | |
| 29 | |
| 30: FizzBuzz | |
| 31 | |
| 32 | |
| 33: Fizz | |
| 34 | |
| 35: Buzz | |
| 36: Fizz | |
| 37 | |
| 60: FizzBuzz | |
| 61 | |
| 62 | |
| 63: Fizz | |
| 64 | |
| 58 | |
| 59 | |
| 10: Buzz | |
| 11 | |
| 12: Fizz | |
| 13 | |
| 14 | |
| 15: FizzBuzz | |
| 16 | |
| 17 | |
| 18: Fizz | |
| 57: Fizz | |
| 5: Buzz | |
| 6: Fizz | |
| 7 | |
| 8 | |
| 9: Fizz | |
| 3: Fizz | |
| 4 | |
| 56 | |
| 1 | |
| 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment