Skip to content

Instantly share code, notes, and snippets.

@jozefg
Created November 14, 2014 19:24
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 jozefg/9e7c3b85e8012bcfbee5 to your computer and use it in GitHub Desktop.
Save jozefg/9e7c3b85e8012bcfbee5 to your computer and use it in GitHub Desktop.
Lousy Rust Code
use std::io::stdin;
fn fizzbuzz (n : int) -> String {
match (n % 3 == 0, n % 5 == 0) {
(true, true) => "FizzBuzz".to_string(),
(false, true) => "Fizz".to_string(),
(true, false) => "Buzz".to_string(),
(false, false) => n.to_string()
}
}
fn main () {
print!("Enter a number: ");
let input_line =
stdin()
.read_line()
.ok()
.expect("Failed to read line");
let trimmed_slice = input_line.as_slice().trim_right_chars('\n');
let bound = from_str(trimmed_slice).expect("Not an int!");
for i in range(1, 1 + bound) { // bound + 1 fails with "type must of bound must be known"
println!("{}", fizzbuzz(i));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment