Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

N*N tic-tac-toe matrix

(defun build-straights-matrice (n)
    "Declaring variables"
    (setq temp '())
    (setq horizontal '())
    (setq vertical '())
    (setq diagonal '())
    (setq master '())

    "For building the horizontal set."    
    (loop for i from 1 to (* n n)
        do (if (not (eq (mod i n) 0))
                (setq temp (append temp (list i)))
            (progn
                (setq temp (append temp (list i)))
                (setq horizontal (append horizontal (list temp)))
                (setq temp ()))))
    
    "For building the vertical set."
    (loop for i from 1 to n
        do (loop for j in horizontal
                do (setq temp (append temp (list (nth (1- i) j)))))
                    (setq vertical (append vertical (list temp)))
                    (setq temp ()))
    
    "For building the left diagonal."
    (setq temp-counter 0)
    (loop for j in horizontal
        do (setq temp (append temp (list (nth temp-counter j))))
            (setq temp-counter (1+ temp-counter)))
    (setq diagonal (append diagonal (list temp)))
    (setq temp ())

    "For building the right diagonal."
    (setq temp-counter (- n 1))
    (loop for j in horizontal
        do (setq temp (append temp (list (nth temp-counter j))))
            (setq temp-counter (1- temp-counter)))
    (setq diagonal (append diagonal (list temp)))
    
    "Merging all..."
    (setq master (append (append master horizontal) (append (append master vertical) (append master diagonal)))))

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.