Function: 5x5-solve-rotate-left

5x5-solve-rotate-left is an interactive and byte-compiled function defined in 5x5.el.gz.

Signature

(5x5-solve-rotate-left &optional N)

Documentation

Rotate left by N the list of solutions in 5x5-solver-output.

If N is not supplied rotate by 1, that is to say put the last element first in the list.

The 5x5 game has in general several solutions. For grid size=5, there are 4 possible solutions. When function
5x5-solve-suggest (press M-x 5x5-solve-suggest (5x5-solve-suggest)) is called the
solution that is presented is the one that needs least number of strokes --- other solutions can be viewed by rotating through the list. The list of solution is ordered by number of strokes, so rotating left just after calling 5x5-solve-suggest will show the solution with second least number of strokes, while rotating right will show the solution with greatest number of strokes.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/play/5x5.el.gz
(defun 5x5-solve-rotate-left (&optional n)
  "Rotate left by N the list of solutions in 5x5-solver-output.

If N is not supplied rotate by 1, that is to say put the last
element first in the list.

The 5x5 game has in general several solutions.  For grid size=5,
there are 4 possible solutions.  When function
`5x5-solve-suggest' (press `\\[5x5-solve-suggest]') is called the
solution that is presented is the one that needs least number of
strokes --- other solutions can be viewed by rotating through the
list.  The list of solution is ordered by number of strokes, so
rotating left just after calling `5x5-solve-suggest' will show
the solution with second least number of strokes, while rotating
right will show the solution with greatest number of strokes."
  (interactive "P" 5x5-mode)
  (let ((len  (length 5x5-solver-output)))
    (when (>= len 3)
      (setq n (if (integerp n) n 1)
	    n (mod n (1- len)))
      (unless (eq n 0)
	(setq n  (- len n 1))
	(let* ((p-tail (last 5x5-solver-output (1+ n)))
	       (tail (cdr p-tail))
	       (l-tail (last tail)))
	  ;;
	  ;;  For n = 2:
	  ;;
	  ;;  +--+--+   +--+--+   +--+--+   +--+--+   +--+--+
	  ;;  |M | ---->|S1| ---->|S2| ---->|S3| ---->|S4| ----> nil
	  ;;  +--+--+   +--+--+   +--+--+   +--+--+   +--+--+
	  ;;    ^                   ^         ^         ^
	  ;;    |                   |         |         |
	  ;;    + 5x5-solver-output |         |         + l-tail
	  ;;			    + p-tail  |
	  ;;			              + tail
	  ;;
	  (setcdr l-tail (cdr 5x5-solver-output))
	  (setcdr 5x5-solver-output tail)
	  (unless (eq p-tail 5x5-solver-output)
	    (setcdr p-tail nil)))
	(5x5-draw-grid (list 5x5-grid))
	(5x5-position-cursor)))))