Sort by

recency

|

147 Discussions

|

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

  • + 1 comment

    Haskell recursive solution

    f :: Int -> [Int] -> [Int]
    f n [] = []
    f n (x:arr) 
        | x<n = x : f n arr
        | otherwise = f n arr
    
    -- The Input/Output section. You do not need to change or modify this part
    main = do 
        n <- readLn :: IO Int 
        inputdata <- getContents 
        let 
            numbers = map read (lines inputdata) :: [Int] 
        putStrLn . unlines $ (map show . f n) numbers