You can use the equality function (=) if the ones and zeroes have to
be in the same exact places in the matrix:

user=> (= [1 0] [1 0])
true
user=> (= [1 0] [0 1])
false
user=> (= [[1 0] [0 1]] [[1 0] [0 1]])
true
user=> (= [[1 0] [0 1]] [[1 0] [1 0]])
false
user=>

If the shapes can be offset inside the matrix, then I'm afraid you
will have to device a more complex algorithm.

Also, less idiomatically I suppose, if the matrices are always four by
four cells, then the whole matrix can be represented in a short (the
number type short). :p

On Wed, May 19, 2010 at 8:39 AM, Thomas Kjeldahl Nilsson
<tho...@kjeldahlnilsson.net> wrote:
> Hello, newbie question here. :)
>
> I'm writing a Tetris game to teach myself Clojure, and I'm trying to
> keep the code ideomatic as I go along.
> One of the most basic parts of the underlying model is representing
> the pieces and playing field as two dimensional matrices.
>
> This is an L shaped playing piece (represented by a two dimensional
> vector literal):
>
> (def L-shape
> [
>  [0 1 0 0]
>  [0 1 0 0]
>  [0 1 1 0]
>  [0 0 0 0]
> ])
>
> I want to check if other matrices of same size have the same shape,
> ie. are the 1's and 0's in the same places in the compared matrix?
>
> I suppose the most straight-forward way is write a function which
> steps through the two matrices simultaneously, comparing
> corresponding elements one by one.
>
> My question: is there a more elegant way of determining equivalence of
> collection structures like these in Clojure?
>
>
> --
> Cheers,
> Thomas Kjeldahl Nilsson
> http://kjeldahlnilsson.net
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en



-- 
Venlig hilsen / Kind regards,
Christian Vest Hansen.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to