Sort by

recency

|

192 Discussions

|

  • + 0 comments

    To repeat each element in a list a given number of times, use a simple list comprehension like: return [x for x in arr for _ in range(num)]. It preserves the order and repeats each item num times. Learn more cool comparisons like this in the Doraemon X APK mod vs official comparison.

  • + 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