Clojure (64 54 4431 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 byBy counting on the REPL to print out the resultant collection and coding the codefunction using the #()
shortcut we can be reducedreduce it 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#(["1" "i" "-1" "-i"](mod % 4)) [0 1 2 3 4 5 6 7 88])
which prints
("1" 9"i" 10"-1" 11]"-i" "1" "i" "-1" "-i" "1")
Share and enjoy.