Clojure (64 54 44 chars)
(defn i2n[n](println(case(mod n 4) 1 "i" 2 "-1" 3 "-i" 0 "1")))
Edit
Per @SeanAllred's suggestion, here's a version which uses a literal vector instead of a case
function:
(defn i2n[n](println (["1" "i" "-1" "-i"] (mod n 4))))
Edit 2
And by counting on the REPL to print out the resultant collection the code can be reduced to
(defn i2n[n](["1" "i" "-1" "-i"] (mod n 4)))
(Which is actually much more Clojure/Lisp-ish as the function now actually returns the generated result, allowing the function to be used with map
, as in
(map i2n [0 1 2 3 4 5 6 7 8 9 10 11])
Share and enjoy.