Skip to main content
Modified to return the result rather than just printing it, and use the #() function literal syntax
Source Link

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.

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.

Clojure (64 54 31 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

By counting on the REPL to print out the resultant collection and coding the function using the #() shortcut we can reduce it to

#(["1" "i" "-1" "-i"](mod % 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 #(["1" "i" "-1" "-i"](mod % 4)) [0 1 2 3 4 5 6 7 8])

which prints

("1" "i" "-1" "-i" "1" "i" "-1" "-i" "1")

Share and enjoy.

Modified to return the result rather than just printing it
Source Link

Clojure (64 5454 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.

Clojure (64 54 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))))

Share and enjoy.

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.

Added version which uses a vector literal instead of a case function call
Source Link

Clojure (6464 54 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))))

Share and enjoy.

Clojure (64 chars)

(defn i2n[n](println(case(mod n 4) 1 "i" 2 "-1" 3 "-i" 0 "1")))

Share and enjoy.

Clojure (64 54 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))))

Share and enjoy.

Source Link
Loading