Skip to content

Instantly share code, notes, and snippets.

@skade
Created May 15, 2018 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skade/8049601bc7469f94c5d7d947d5229e55 to your computer and use it in GitHub Desktop.
Save skade/8049601bc7469f94c5d7d947d5229e55 to your computer and use it in GitHub Desktop.
FastBuzz
extern crate itoa;
use std::io::Write;
use std::io::BufWriter;
pub fn main() {
let stdout = std::io::stdout();
let mut stdout = BufWriter::new(stdout);
let mut acc = 810092048;
for i in 1..100_000_000_u32 {
let c = acc & 3;
match c {
0 => {
itoa::write(&mut stdout, i).unwrap();
stdout.write(b"\n").unwrap();
},
1 => {
stdout.write(b"Fizz\n").unwrap();
},
2 => {
stdout.write(b"Buzz\n").unwrap();
},
3 => {
stdout.write(b"FizzBuzz\n").unwrap();
},
_ => { unimplemented!() }
}
acc = acc >> 2 | c << 28
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment