-
Programming exercises to sharpen skills.
Archive for category Programming
links for 2009-09-10
Sep 10
links for 2009-02-25
Feb 25
-
Stack Overflow is a collaboratively edited question and answer site for programmers — regardless of platform or language. It’s 100% free, no registration required.
Languages that I like to dabble in:
Clojure
(defn fact [n] (apply * (range 2 (inc n))))
Scala
def fact(x: BigInt): BigInt = if (x == 0) 1 else x * fact(x - 1)
JavaScript
function fact(n) {
return (n == 0) ? 1 : n * fact(n - 1);
}
Groovy
def fact(n) {
(2..n).inject(1) { fact, i | fact * i }
}
Python / Jython
def fact(x): return (1 if x==0 else x * fact(x-1))
Ruby
def fact(n)
(1 .. n).inject{|a, b| a*b}
end