Created
November 14, 2014 19:24
-
-
Save jozefg/9e7c3b85e8012bcfbee5 to your computer and use it in GitHub Desktop.
Lousy Rust Code
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
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