Last active
January 25, 2021 20:55
-
-
Save niczky12/120c069f52762ee05e908c49f24f1199 to your computer and use it in GitHub Desktop.
Fizzbuzz 4
This file contains 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
function fizzbuzz(n) | |
numbers = 1:n | |
# first we convert the numbers to strings | |
result = string.(numbers) | |
result[rem.(numbers, 3) .== 0] .= "Fizz" | |
result[rem.(numbers, 5) .== 0] .= "Buzz" | |
result[(rem.(numbers, 3) .== 0) .* (rem.(numbers, 5) .== 0)] .= "FizzBuzz" | |
return result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment