I'm quite new to clojure so still trying to learn... well a LOT of stuff. Right now I'm stuck on trying to get some output to display properly. Here is my function:
;function 7 - display the board
(defn display [small medium large]
(let [board (loop [i 0 boardVector [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]
;(prn (bit-test small i)(bit-test medium i)(bit-test large i))
(if (< i 16)
(cond
;nothing exists
(and (not(bit-test small i))(not(bit-test medium i))(not(bit-test large i)))
(recur (+ i 1) (assoc boardVector i (+ (nth boardVector i) 0)))
;only small bit exists
(and (bit-test small i)(not(bit-test medium i))(not(bit-test large i)))
(recur (+ i 1) (assoc boardVector i (+ (nth boardVector i) 1)))
;small and medium exists on square
(and (bit-test small i)(bit-test medium i)(not(bit-test large i)))
(recur (+ i 1) (assoc boardVector i (+ (nth boardVector i) 3)))
;only medium exists on square
(and (not(bit-test small i))(bit-test medium i)(not(bit-test large i)))
(recur (+ i 1) (assoc boardVector i (+ (nth boardVector i) 2)))
;medium and large exists on square
(and (not(bit-test small i))(bit-test medium i)(bit-test large i))
(recur (+ i 1) (assoc boardVector i (+ (nth boardVector i) 6)))
;only large exists on square
(and (not(bit-test small i))(not(bit-test medium i))(bit-test large i))
(recur (+ i 1) (assoc boardVector i (+ (nth boardVector i) 4)))
;all three exists on square
(and (bit-test small i)(bit-test medium i)(bit-test large i))
(recur (+ i 1) (assoc boardVector i (+ (nth boardVector i) 7)))
)
boardVector)
)
]
(prn board)
)
)
Here is what I'm using to pass as arguments:
(display 2r1001000100 2r101001000 2r111000000)
This function takes bit variables (that are no more than 16 in length...), and calculates a final vector depending on which bits are set. a small is worth 1, medium worth 2, large worth 4. This is why I have that condition statement outlining each different possibility, excluding the possibility of having a small and large, and no medium set at the same time.
Anyhow, if none of that makes sense, here's the actual question: How do I get my current output that displays as:
[0 0 1 2 0 0 7 4 6 1 0 0 0 0 0 0]
nil
To make it display like this?
0 0 1 2
0 0 7 4
6 1 0 0
0 0 0 0
I've tried using functions such as apply, map, str, interpose... but I never could figure out what the heck I was doing wrong with them. Currently I have the output displayed as a side-effect (i think that is the correct name for that...), but it's always returning nil from the output of the prn function. Dunno how to get rid of that either. Would appreciate any help!