Skip to content

Instantly share code, notes, and snippets.

@SamRH
Created August 29, 2013 01:58
Show Gist options
  • Save SamRH/6373497 to your computer and use it in GitHub Desktop.
Save SamRH/6373497 to your computer and use it in GitHub Desktop.
// the various moudules im going to use
use std::int;
use std::io;
// see comment for bang but 3
fn fizz(i: int) -> bool {
i % 3 == 0
}
// function using an implicit return to evaluate divisibility by 5
fn bang(i: int) -> bool {
i % 5 == 0
}
// main function aka entry point
fn main() {
// iterate a range, assigning each iter to num
for int::range(1, 101) |num| {
// print a line...
io::println(
// match a tuple (match is kinda like C-switch)
match (fizz(num), bang(num)) {
(true, true) => ~"FizzBuzz",
(true, false) => ~"Fizz",
(false, true) => ~"Buzz",
_ => fmt!("%d", num) /* could have matched
w/(false, false), _ is all */
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment