Sort 87 Discussions, By:
Please Login in order to post a comment
Another solution approach in Scala using for expression:
for (i <- arr if i < delim) yield i
In Scala, assuming we're not able to use filter, we could instead use the fact that flatMap will filter out values of None.
arr.flatMap(a => if (a < delim) Some(a) else None)
f n arr = filter (< n) arr
f n arr = [ a | a <- arr , a < n ]
f = filter . (>)
anytime you have same dangling arguments at the end on both sides, you can get rid of it and be point free, like this
f n = filter (< n)
matter of taste, whether you prefer "f(x) = sin(x)" or "f = sin"... But anyway, the exercise is to write your own filter function and not use the built-in one.
Another Clojure solution. Not lazy unfortunately.
(fn[delim lst] (reduce #(if (< %2 delim) (conj %1 %2) %1)  lst))
yes this is work great, when i face the Netgear Error 651 issue I simply input this method to solve out the issue quickly.thanks for your contribution. it's really help me a lot.
Here is how to read the stdin for this question in Ocaml:
let f n arr =
(* implementation *)
let () =
(* first line is parsed as the first arg to f *)
let num = int_of_string (read_line ()) in
(* the rest until EOF are parsed into an array for second arg *)
f num (
let rec aux arr =
let input = read_line () in
match input with
| "" -> arr
| a -> aux (arr @ [int_of_string a])
with End_of_file -> arr
in aux  )
I decided I didn't want to use the Enum library at all and implemented my Elixir solution using pure naive comprehensions. One of the interesting things about recursion is that the list is represented backwards in memory immediately after make_list is run, but since filter walks the list again and places the last element in the first position, everything comes back out in the correct order once it is time to print :D
defmodule NaiveList do
def print(), do:
def print([value | rest]) do
def filter(limit, list), do:
filter(limit, list, )
def filter(_limit, , output), do:
def filter(limit, [value | rest], output) when value < limit, do:
filter(limit, rest, [value | output])
def filter(limit, [_value| rest], output), do:
filter(limit, rest, output)
def make_list(), do:
defp make_list(""<>number, list), do:
make_list(IO.gets(""), [(number |> String.trim |> String.to_integer) | list])
defp make_list(:eof, list), do:
n = IO.gets("") |> String.trim |> String.to_integer
list = NaiveList.make_list()
NaiveList.filter(n, list) |> NaiveList.print
I am not particularly convinced that the specifications are tested fully. I used list comprehension to circumvent the use of "filter" and it worked.
Hi @JCrazafy, thanks for pointing. I have reworded the constraint. It is suggested to write own implementation, not enforced.
(fn [delim lst] (filter #(< % delim) lst))
the whole point is not to use built in filter
An F# solution
let main args =
let x = Console.ReadLine() |> int
let numbers =
Seq.initInfinite (fun _ -> Console.ReadLine())
|> Seq.takeWhile (String.IsNullOrWhiteSpace >> not)
|> Seq.filter (fun v -> v |> int < x)
|> Seq.iter (printf "%s\n")
The following part which will be going to get the part that will be enable to manage the part accroding to the best way so for that it wil be hvaing the best to get the array code that firefox couldn't load xpcom represneted immeditaley recursion for it .
My firefox also couldn't load xpcom. Can U help me out.
Please mail me at Gmail Klantenservice
Any Lisp or Racket solutions?
This? Input thanks to @abhiranjan
(let ([x (read)]) x))
(let ([x (read)])
(if (eof-object? x)
(cons x (read-list)))))
(let ([t (read-threshold)]
(for ([x l])
(if (< x t)
(printf "~a\n" x)