(n: Int) => (2 to n) |> (r => r.foldLeft(r.toSet)((ps, x) => if (ps(x)) ps -- (x * x to n by x) else ps))
It requires the forward pipe operator, such as the one provided by Scalaz or the one defined here.
Random thoughts of an IT worker in the stone age of computer science.
(n: Int) => (2 to n) |> (r => r.foldLeft(r.toSet)((ps, x) => if (ps(x)) ps -- (x * x to n by x) else ps))
This one liner would be much more readable as a multiline expression... Too many parentheses.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete