Sort by

recency

|

191 Discussions

|

  • + 0 comments

    Looking for expert support in building design and safety? At FA Engineering, we offer reliable structural engineering services and architectural service tailored to residential, commercial, and industrial projects. Our team ensures every structure is both functional and compliant with modern standards.

  • + 0 comments

    For Ocaml

    let rec duplicate_arr n ch = 
        if (n > 0) then ch:: duplicate_arr (n-1) ch
        else []
        
    let rec f n arr = match arr with 
        | [] -> []
        | h::t -> (duplicate_arr n h)@(f n t)
    
  • + 0 comments
    open System;
    
    let n = Console.ReadLine () |> int
    
    let rec read arr =
        match Console.ReadLine () with
        | x when String.IsNullOrEmpty x -> arr
        | x -> x :: arr |> read
    
    read []
    |> List.rev
    |> List.collect (fun x -> List.replicate n x)
    |> Seq.iter (fun x -> printfn "%s" x)
    
  • + 0 comments
    f :: Int -> [Int] -> [Int]
    f n [] = []
    f n (x:xs) =  (helper (n) (x:xs)) ++ f (n) xs
        where helper n (x:xs)   | n==0 = []
                                | otherwise = x:helper (n-1) (x:xs)       
    

    Haskell beginner here

  • + 0 comments

    Scala, such that I am new to Scala and functional programming

    def getNumElements(s: Int, element: Int, result: List[Int]): List[Int] = {
        if (s > 0) {
            getNumElements(s - 1, element, result :+ element)
        } else {
            result
        }
    }
    
    def f(num: Int, arr: List[Int], result: List[Int] = List(),
          repeater: (Int, Int, List[Int]) => List[Int] = getNumElements
         ): List[Int] = {
        if (arr.size > 0) {
            f(num, arr.tail, result ::: repeater(num, arr.head, List()))
        } else {
            result
        }
    }