Function: mpuz-random-puzzle

mpuz-random-puzzle is a byte-compiled function defined in mpuz.el.gz.

Signature

(mpuz-random-puzzle)

Documentation

Draw random values to be multiplied in a puzzle.

Source Code

;; Defined in /usr/src/emacs/lisp/play/mpuz.el.gz
;; To build a puzzle, we take two random numbers and multiply them.
;; We also take a random permutation for encryption.
;; The random numbers are only use to see which digit appears in which square
;; of the board. Everything is stored in individual squares.
;;---------------------------------------------------------------------------
(defun mpuz-random-puzzle ()
  "Draw random values to be multiplied in a puzzle."
  (mpuz-build-random-perm)
  (fillarray mpuz-board nil)		; erase the board
  ;; A,B,C,D & E, are the five rows of our multiplication.
  ;; Choose random values, discarding cases with leading zeros in C or D.
  (let* ((A (if mpuz-allow-double-multiplicator (+ 112 (random 888))
	      (+ 125 (random 875))))
	 (min (1+ (/ 999 A)))
	 (B1 (+ min (random (- 10 min))))
	 B2 C D E)
    (while (if (= B1 (setq B2 (+ min (random (- 10 min)))))
	       (not mpuz-allow-double-multiplicator)))
    (setq C (* A B2)
	  D (* A B1)
	  E (+ C (* D 10)))
    ;; Individual digits are now put on their respective squares.
    ;; [NB: A square is a pair (row . column) of the screen.]
    (mpuz-put-number-on-board A	2		 9 7 5)
    (mpuz-put-number-on-board (+ (* B1 10) B2) 4 9 7)
    (mpuz-put-number-on-board C	6		 9 7 5 3)
    (mpuz-put-number-on-board D 8		   7 5 3 1)
    (mpuz-put-number-on-board E	10		 9 7 5 3 1)))