3 ms·
Going on a tangent, but that Clojure code looks incredibly convoluted. Compare to this: next = (n) -> "#{n}".split('').reduce ((p,c) -> p + c*c), 0
by ricardobeat 12y ago
Going on a tangent, but that Clojure code looks incredibly convoluted. Compare to this:
next = (n) -> "#{n}".split('').reduce ((p,c) -> p + c*c), 0
happy = (n, set = []) ->
return false if n in set
return true if n is 1
happy next(n), set.concat(n)
console.log(n, happy n) for n in [1..100]
That complexity certainly makes it harder to solve the problem under pressure. This is really an example of an interview process that focuses on specific language skills and not actual programming abilities.
- grayclhn 12y agoTo be fair, from the description of the job it looks like language specific skills matter.
- QuercusMax 12y agoWhat language is this?
- nadaviv 12y agoCoffeeScript.
- wging 12y agoThe Clojure in the article isn't idiomatic, as the author admits. You could do something very similar in Clojure, though the details are different. In fact when I tried this problem my solution was shaped about like yours.