Zachary Turner <ztur...@bindview.com> wrote:
I've got a 3x3 matrix, stored as ((r1c1 r1c2 r1c3) (r2c1 r2c2 r2c3) (r3c1 >r3c2 r3c3)). I want to check if any of the columns have the same three >elements. It's easy for rows, I can just use
(or
(every #'equal (car matrix))
(every #'equal (cadr matrix))
(every #'equal (caddr matrix)))
Actually, that doesn't work. EVERY passes a single element to the test function, but EQUAL requires two arguments. What you need is:
(or (every #'(lambda (x) (equal x (caar matrix)))
(cdar matrix))
(every #'(lambda (x) (equal x (caadr matrix)))
(cdadr matrix))
(every #'(lambda (x) (equal x (caaddr matrix)))
(cdaddr matrix)))
My questions are:
a) Can I do this more elegantly using a mapxxx function?
(defun (all-elements-equal (list)
(destructuring-bind (head . tail) list
(every #'(lambda (x) (equal x head))
tail))))
Barry Margolin wrote:
Zachary Turner <ztur...@bindview.com> wrote:
I've got a 3x3 matrix, stored as ((r1c1 r1c2 r1c3) (r2c1 r2c2 r2c3) (r3c1 >> >r3c2 r3c3)). I want to check if any of the columns have the same three
elements. It's easy for rows, I can just use
(or
(every #'equal (car matrix))
(every #'equal (cadr matrix))
(every #'equal (caddr matrix)))
(has-diagonal-3x3 '((x o o)(o x _)
(has-diagonal-3x3 '((x o o)(o _ _)
(has-diagonal-3x3 '((x o o)(o o x)
(has-diagonal-3x3 '((x o o)(o o x)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 403 |
Nodes: | 16 (2 / 14) |
Uptime: | 44:11:29 |
Calls: | 8,407 |
Calls today: | 2 |
Files: | 13,171 |
Messages: | 5,905,028 |