Created
November 21, 2019 09:17
-
-
Save htsign/34661d31dff8a151524015fc77499e58 to your computer and use it in GitHub Desktop.
FizzBuzz
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
proc fizzBuzz(n: int) = | |
let (x, y) = (n mod 3, n mod 5) | |
let s = | |
if (x, y) == (0, 0): "FizzBuzz" | |
elif x == 0: "Fizz" | |
elif y == 0: "Buzz" | |
else: $n | |
echo s | |
for x in 1..100: | |
fizzBuzz x |
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 "collections" | |
actor FizzBuzz | |
let _env: Env | |
new create(env': Env) => | |
_env = env' | |
be fizz_buzz(x: I32) => | |
let s = | |
match (x % 3, x % 5) | |
| (0, 0) => "FizzBuzz" | |
| (0, _) => "Fizz" | |
| (_, 0) => "Buzz" | |
else x.string() end | |
_env.out.print(s) | |
actor Main | |
new create(env': Env) => | |
let fb = FizzBuzz(env') | |
for x in Range[I32](1, 101) do | |
fb.fizz_buzz(x) | |
end |
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
fn fizz_buzz(n: i32) { | |
let s = | |
match (n % 3, n % 5) { | |
(0, 0) => "FizzBuzz".to_string(), | |
(0, _) => "Fizz".to_string(), | |
(_, 0) => "Buzz".to_string(), | |
_ => n.to_string(), | |
}; | |
println!("{}", s); | |
} | |
fn main() { | |
for x in 1..101 { | |
fizz_buzz(x); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment