Sort by

recency

|

150 Discussions

|

  • + 0 comments

    In REXX, you can filter integers less than a given delimiter by reading the delimiter first with parse pull, then looping through the input with do while lines() > 0. For each number, use if num < delim then say num to print values below the limit. This keeps the original order, like selecting the right tools in iPhone Stardew Valley.

    Ask ChatGPT

  • + 0 comments

    You are expected to write a custom filter function without using built-in methods. Just return a new list with elements less than the delimiter while preserving order. Make sure your function matches the given signature for your language.

  • + 0 comments

    The generate code by HR is bad. Haskell is a functional programming language and it should be a declarative style rather than imperative.

    for example this processes whole input like a stream. Betpkr Much more elegant.

    filterIt :: [Int] -> [String] filterIt (a:xs) = map show $ filter (\x -> x < a) xs

    main = interact $ unlines . filterIt. map read. words

  • + 0 comments

    F#

    let readStringList() = 
        let rec loop acc = 
            let input = Console.ReadLine() 
            if input = null then 
                List.rev acc
            else 
                loop (input :: acc) 
        loop []
    
    let delimiter = Console.ReadLine() |> int
    
    readStringList() 
    |> List.map int // Convert string to int
    |> List.filter (fun x -> x < delimiter) // Filter the list 
    |> List.iter (printfn "%d") // Print the list
    
  • + 0 comments

    Scala

    def checkHeadLessThanDelim(delim: Int, head: Int, result: List[Int]
                              ): List[Int] = {
        if (head < delim) {
            result :+ head
        } else {
            result
        }
    }
    
    def f(delim: Int, arr: List[Int], result: List[Int] = List(),
         headChecker: (Int, Int, List[Int]) => List[Int] = checkHeadLessThanDelim
         ): List[Int] = {
        if (arr.size > 0) {
            f(delim, arr.tail, headChecker(delim, arr.head, result))
        } else {
            result
        }
    }