Sort by

recency

|

148 Discussions

|

  • + 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
        }
    }
    
  • + 0 comments

    Thanks for the solution, https://www.lightweightflanges.com/ I was looking for it for my site

  • + 0 comments

    filterLessThan :: Int -> [Int] -> [Int] filterLessThan _ [] = [] filterLessThan n (x:xs) | x < n = x : filterLessThan n xs | otherwise = filterLessThan n xs

    main :: IO () main = do n <- readLn :: IO Int inputdata <- getContents let numbers = map read (lines inputdata) :: [Int] putStrLn . unlines $ (map show . filterLessThan n) numbers

    Thanks for sharing this valuable JavaScript filter; otherwise, I often encounter bugs and find myself having to visit OSCracks platforms that offer solutions to programming errors.