## DEV Community is a community of 602,687 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

loading...

# Discussion on: FizzBuzz challenge in as many languages as possible JedDevs

Language: Lua
Code:

``````function FizzBuzz()
for i = 1,100 do
--print(i)
if i%3 == 0 and i%5 == 0 then
print("FizzBuzz")
elseif i%3 == 0 then
print("Fizz")
elseif i%5 == 0 then
print("Buzz")
else
print(i)
end
end
end
FizzBuzz()
``````

Other/info: I guess I'll start the challenge off.
This is a pretty simple function in lua of the FizzBuzz challenge. Vasile Rotaru

Language: OCaml
Code:

``````let fizzbuzz n =
let rec loop i max div3 div5 =
if i < max then
match i = div3, i = div5 with
| true, true   -> print_endline "FizzBuzz"; loop (i + 1) max (div3 + 3) (div5 + 5)
| true, false  -> print_endline "Fizz"; loop (i + 1) max (div3 + 3) div5
| false, true  -> print_endline "Buzz"; loop (i + 1) max div3 (div5 + 5)
| false, false -> print_endline (string_of_int i); loop (i + 1) max div3 div5
in
loop 1 n 3 5

let _ = fizzbuzz 100
`````` JedDevs

I've learnt a lot since this old thread, here's how i'd attempt this question in an interview today:

``````
-- FizzBuzz

local function isDivisible(num: number, by: integer)
return num % by == 0
end

local function result(number)
local str = ""

if isDivisible(number, 3) then
str = str.."Fizz"
end

if isDivisible(number, 5) then
str = str.."Buzz"
end

return (str ~= "" and str) or number
end

for i = 1, 100 do
print(result(i))
end
``````