Ad

clojure

Code
Diff
  • module Solution where
    
    fizzbuzz :: [String] -> Int -> Int -> [String]
    fizzbuzz acc i n
      | n < i = acc
      | otherwise = fizzbuzz (s : acc) i (n - 1)
      where
        s = case (mod n 3, mod n 5) of
          (0, 0) -> "fizzbuzz"
          (0, _) -> "fizz"
          (_, 0) -> "buzz"
          _ -> show n
    • def rec(acc,i,n):
    • done=i>n
    • match done:
    • case True:
    • return acc
    • case _:
    • fb=not (i%3 or i%5)
    • f=not i%3
    • b=not i%5
    • match fb:
    • case True:
    • return rec(acc+["fizzbuzz"],i+1,n)
    • case _:
    • match f:
    • case True:
    • return rec(acc+["fizz"],i+1,n)
    • case _:
    • match b:
    • case True:
    • return rec(acc+["buzz"],i+1,n)
    • case _:
    • return rec(acc+[str(i)],i+1,n)
    • def fizzbuzz(n):
    • return rec([],1,n)
    • # def fizzbuzz(n):
    • # acc=[]
    • # i=1
    • # while i<=n:
    • # if not (i%3 or i%5):
    • # acc.append("fizzbuzz")
    • # elif not i%3:
    • # acc.append("fizz")
    • # elif not i%5:
    • # acc.append("buzz")
    • # else:
    • # acc.append(str(i))
    • # i+=1
    • # return acc
    • module Solution where
    • fizzbuzz :: [String] -> Int -> Int -> [String]
    • fizzbuzz acc i n
    • | n < i = acc
    • | otherwise = fizzbuzz (s : acc) i (n - 1)
    • where
    • s = case (mod n 3, mod n 5) of
    • (0, 0) -> "fizzbuzz"
    • (0, _) -> "fizz"
    • (_, 0) -> "buzz"
    • _ -> show n