;; these are various function supporting mini rubik's cube ;; operations ;; Representation: ;; ;; |t11 t12| ;; |t21 t22| ;; |l11 l12| |f11 f12| |r11 r12| |a11 a12| ;; |l21 l22| |f21 f22| |r21 r22| |a21 a22| ;; |b11 b12| ;; |b21 b22| ;; ;; Data structure: ;; ((f11 f12 f21 f22) (t11 t12 t21 t22) (b11 b12 b21 b22) ;; (l11 l12 l21 l22) (r11 r12 r21 r22) (a11 a12 a21 a22)) ;; ;; ;; Operators ;; ;; RotateFront1: rotate front 1 time clockwise (defun RotateFront1 (cube) (let ((front (copy-list (first cube))) (top (copy-list (second cube))) (bottom (copy-list (third cube))) (left (copy-list (fourth cube))) (right (copy-list (fifth cube))) (back (copy-list (sixth cube)))) ;; rotate front face (list (list (third front) (first front) (fourth front) (second front)) ;; modify top (list (first top) (second top) (fourth left) (second left)) ;; modify bottom (list (third right) (first right) (third bottom) (fourth bottom)) ;; modify left (list (first left) (first bottom) (third left) (second bottom)) ;; modify right (list (third top) (second right) (fourth top) (fourth right)) ;; copy back back))) ;; RotateFront2: rotate front 2 times clockwise (defun RotateFront2 (cube) (RotateFront1 (RotateFront1 cube))) ;; RotateFront3: rotate front 3 times clockwise (defun RotateFront3 (cube) (RotateFront1 (RotateFront2 cube))) ;; RotateTop1: rotate top 1 time clockwise (defun RotateTop1 (cube) (let ((front (copy-list (first cube))) (top (copy-list (second cube))) (bottom (copy-list (third cube))) (left (copy-list (fourth cube))) (right (copy-list (fifth cube))) (back (copy-list (sixth cube)))) ;; rotate front face (list (list (first right) (second right) (third front) (fourth front)) ;; rotate top (list (third top) (first top) (fourth top) (second top)) ;; copy bottom bottom ;; modify left (list (first front) (second front) (third left) (fourth left)) ;; modify right (list (first back) (second back) (third right) (fourth right)) ;; modify back (list (first left) (second left) (third back) (fourth back))))) ;; RotateTop2: rotate top 2 times clockwise (defun RotateTop2 (cube) (RotateTop1 (RotateTop1 cube))) ;; RotateTop3: rotate top 3 times clockwise (defun RotateTop3 (cube) (RotateTop1 (RotateTop2 cube))) ;; RotateBottom1: rotate bottom 1 time clockwise (defun RotateBottom1 (cube) (let ((front (copy-list (first cube))) (top (copy-list (second cube))) (bottom (copy-list (third cube))) (left (copy-list (fourth cube))) (right (copy-list (fifth cube))) (back (copy-list (sixth cube)))) ;; rotate front face (list (list (first front) (second front) (third left) (fourth left)) ;; copy top top ;; rotate bottom (list (third bottom) (first bottom) (fourth bottom) (second bottom)) ;; modify left (list (first left) (second left) (third back) (fourth back)) ;; modify right (list (first right) (second right) (third front) (fourth front)) ;; modify back (list (first back) (second back) (third right) (fourth right))))) ;; RotateBottom2: rotate bottom 2 times clockwise (defun RotateBottom2 (cube) (RotateBottom1 (RotateBottom1 cube))) ;; RotateBottom3: rotate bottom 3 times clockwise (defun RotateBottom3 (cube) (RotateBottom1 (RotateBottom2 cube))) ;; RotateLeft1: rotate left 1 time clockwise (defun RotateLeft1 (cube) (let ((front (copy-list (first cube))) (top (copy-list (second cube))) (bottom (copy-list (third cube))) (left (copy-list (fourth cube))) (right (copy-list (fifth cube))) (back (copy-list (sixth cube)))) ;; modify front face (list (list (first top) (second front) (third top) (fourth front)) ;; modify top (list (fourth back) (second top) (second back) (fourth top)) ;; modify bottom (list (first front) (second bottom) (third front) (fourth bottom)) ;; modify left (list (third left) (first left) (fourth left) (second left)) ;; copy right right ;; modify back (list (first back) (third bottom) (third back) (first bottom))))) ;; RotateLeft2: rotate left 2 times clockwise (defun RotateLeft2 (cube) (RotateLeft1 (RotateLeft1 cube))) ;; RotateLeft3: rotate left 3 times clockwise (defun RotateLeft3 (cube) (RotateLeft1 (RotateLeft2 cube))) ;; RotateRight1: rotate right 1 time clockwise (defun RotateRight1 (cube) (let ((front (copy-list (first cube))) (top (copy-list (second cube))) (bottom (copy-list (third cube))) (left (copy-list (fourth cube))) (right (copy-list (fifth cube))) (back (copy-list (sixth cube)))) ;; modify front face (list (list (first front) (second bottom) (third front) (fourth bottom)) ;; modify top (list (first top) (second front) (third top) (fourth front)) ;; modify bottom (list (first bottom) (third back) (third bottom) (first back)) ;; copy left left ;; rotate right (list (third right) (first right) (fourth right) (second right)) ;; modify back (list (fourth top) (second back) (second top) (fourth back))))) ;; RotateRight2: rotate right 2 times clockwise (defun RotateRight2 (cube) (RotateRight1 (RotateRight1 cube))) ;; RotateRight3: rotate right 3 times clockwise (defun RotateRight3 (cube) (RotateRight1 (RotateRight2 cube))) ;; RotateBack1: rotate back 1 time clockwise (defun RotateBack1 (cube) (let ((front (copy-list (first cube))) (top (copy-list (second cube))) (bottom (copy-list (third cube))) (left (copy-list (fourth cube))) (right (copy-list (fifth cube))) (back (copy-list (sixth cube)))) ;; copy front face (list front ;; modify top (list (second right) (fourth right) (third top) (fourth top)) ;; modify bottom (list (first bottom) (second bottom) (first left) (third left)) ;; modify left (list (second top) (second left) (first top) (fourth left)) ;; modify right (list (first right) (fourth bottom) (third right) (third bottom)) ;; rotate back (list (third back) (first back) (fourth back) (second back))))) ;; RotateBack2: rotate back 2 times clockwise (defun RotateBack2 (cube) (RotateBack1 (RotateBack1 cube))) ;; RotateBack3: rotate back 3 times clockwise (defun RotateBack3 (cube) (RotateBack1 (RotateBack2 cube)))