June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,11 +1,9 @@
use std::borrow::Cow; // Allows us to avoid unnecessary allocations
fn main() {
let result = (1..101).map(|n| match (n % 3, n % 5) {
(0, 0) => "FizzBuzz".to_owned(),
(0, _) => "Fizz".to_owned(),
(_, 0) => "Buzz".to_owned(),
_ => n.to_string()
});
for r in result {
println!("{}", r);
}
(1..101).map(|n| match (n % 3, n % 5) {
(0, 0) => "FizzBuzz".into(),
(0, _) => "Fizz".into(),
(_, 0) => "Buzz".into(),
_ => Cow::from(n.to_string())
}).for_each(|n| println!("{}", n));
}

View file

@ -1,11 +1,11 @@
use std::borrow::Cow;
fn main() {
for i in 1..101 {
let word = match (i % 3, i % 5) {
(0, 0) => "FizzBuzz".to_owned(),
(0, _) => "Fizz".to_owned(),
(_, 0) => "Buzz".to_owned(),
_ => i.to_string().to_owned(),
};
println!("{}", word);
println!("{}", match (i % 3, i % 5) {
(0, 0) => "FizzBuzz".into(),
(0, _) => "Fizz".into(),
(_, 0) => "Buzz".into(),
_ => Cow::from(i.to_string()),
});
}
}