We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Filter Array
Filter Array
+ 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
+ 0 comments Thanks for sharing this valueable java script filter otherwise I always got Unexpected End of File error and I need to visit plateforms that are providing solutions of programming errors.
+ 0 comments Some experimenting with currying (I don't know what im doing)
def f(delim: Int, arr: List[Int]): List[Int] = { def myFilter(func: Int => Boolean, arr: List[Int]): List[Int] => List[Int] = { if (arr.isEmpty) (x: List[Int]) => x else if (func(arr.head)) (x: List[Int]) => myFilter(func, arr.tail)(x.:+(arr.head)) else (x: List[Int]) => myFilter(func, arr.tail)(x) } val aFunc: Int => Boolean = x => x < delim myFilter(aFunc, arr)(List()) }
+ 0 comments Proud of my solution, especially since I know 0 haskell f n arr = filter (\e -> e
+ 0 comments
Load more conversations
Sort 143 Discussions, By:
Please Login in order to post a comment