;ELC   
;;; Compiled by pot@pot.cnuce.cnr.it on Tue Mar 18 15:49:45 2003
;;; from file /home/pot/gnu/emacs-pretest.new/lisp/play/mpuz.el
;;; in Emacs version 21.3
;;; with bytecomp version 2.85.4.1
;;; with all optimizations.

;;; This file uses dynamic docstrings, first added in Emacs 19.29.
(if (and (boundp 'emacs-version)
	 (< (aref emacs-version (1- (length emacs-version))) ?A)
	 (or (and (boundp 'epoch::version) epoch::version)
	     (string-lessp emacs-version "19.29")))
    (error "`mpuz.el' was compiled for Emacs 19.29 or later"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(byte-code "\300\301\302\303\304\305\306\307&\210\310\311!\207" [custom-declare-group mpuz nil "Multiplication puzzle." :prefix "mpuz-" :group games random t] 8)
#@51 *Set this to T if you don't want dings on inputs.
(custom-declare-variable 'mpuz-silent 'nil '(#$ . -778) :type 'boolean :group 'mpuz)
#@57 Dings, unless global variable `mpuz-silent' forbids it.
(defalias 'mpuz-ding #[nil "\206 \301\302!\207" [mpuz-silent ding t] 2 (#$ . 919)])
#@33 Hook to run upon entry to mpuz.
(custom-declare-variable 'mpuz-mode-hook 'nil '(#$ . 1067) :type 'hook :group 'mpuz)
#@37 Local keymap to use in Mult Puzzle.
(defvar mpuz-mode-map nil (#$ . 1190))
(byte-code "\204\213 \301 \302\303\304#\210\302\305\304#\210\302\306\304#\210\302\307\304#\210\302\310\304#\210\302\311\304#\210\302\312\304#\210\302\313\304#\210\302\314\304#\210\302\315\304#\210\302\316\304#\210\302\317\304#\210\302\320\304#\210\302\321\304#\210\302\322\304#\210\302\323\304#\210\302\324\304#\210\302\325\304#\210\302\326\304#\210\302\327\304#\210\302\330\331#\210\302\332\333#\210\301\207" [mpuz-mode-map make-sparse-keymap define-key "a" mpuz-try-letter "b" "c" "d" "e" "f" "g" "h" "i" "j" "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "" mpuz-offer-abort "?" describe-mode] 4)
#@454 Multiplication puzzle mode.

You have to guess which letters stand for which digits in the
multiplication displayed inside the `*Mult Puzzle*' buffer.

You may enter a guess for a letter's value by typing first the letter,
then the digit.  Thus, to guess that A=3, type A 3.

To leave the game to do other editing work, just switch buffers.
Then you may resume the game with M-x mpuz.
You may abort a game by typing \<mpuz-mode-map>\[mpuz-offer-abort].
(defalias 'mpuz-mode #[nil "\303\304\305\n!\210\306\307!\207" [major-mode mode-name mpuz-mode-map mpuz-mode "Mult Puzzle" use-local-map run-hooks mpuz-mode-hook] 2 (#$ . 1890) nil])
#@40 Number of errors made in current game.
(defvar mpuz-nb-errors 0 (#$ . 2533))
#@28 Number of games completed.
(defvar mpuz-nb-completed-games 0 (#$ . 2616))
#@42 Number of errors made in previous games.
(defvar mpuz-nb-cumulated-errors 0 (#$ . 2696))
#@42 True if a game is currently in progress.
(defvar mpuz-in-progress nil (#$ . 2791))
#@54 A vector recording which digits have been decrypted.
(defvar mpuz-found-digits (make-vector 10 nil) (#$ . 2880))
(defalias 'mpuz-digit-solved-p '(macro . #[(digit) "\301\302E\207" [digit aref mpuz-found-digits] 3]))
#@38 A permutation from [0..9] to [0..9].
(defvar mpuz-digit-to-letter (make-vector 10 0) (#$ . 3103))
#@38 The inverse of mpuz-digit-to-letter.
(defvar mpuz-letter-to-digit (make-vector 10 0) (#$ . 3207))
(defalias 'mpuz-to-digit '(macro . #[(letter) "\301\302E\207" [letter aref mpuz-letter-to-digit] 3]))
(defalias 'mpuz-to-letter '(macro . #[(digit) "\301\302E\207" [digit aref mpuz-digit-to-letter] 3]))
#@53 Initialize puzzle coding with a random permutation.
(defalias 'mpuz-build-random-perm #[nil "\305\306\307\310\311\312\313\314\315\316\257\n\317\320\n\2050 \321	!\n8\322\n\"	S	I\210\f	I\210\202 +\207" [elem index letters mpuz-digit-to-letter mpuz-letter-to-digit 0 1 2 3 4 5 6 7 8 9 10 nil random delq] 10 (#$ . 3516)])
#@73 The board associates to any digit the list of squares where it appears.
(defvar mpuz-board (make-vector 10 nil) (#$ . 3852))
#@59 Put (last digit of) NUMBER on SQUARE of the puzzle board.
(defalias 'mpuz-put-digit-on-board #[(number square) "\303\246	\n	HBI\207" [number mpuz-board square 10] 5 (#$ . 3983)])
#@61 Check whether all digits have been solved. Return t if yes.
(defalias 'mpuz-check-all-solved #[nil "\300\301\215\207" [found (byte-code "\303\304T\211V\203 	H\204 \nH\203 \305\306\307\"\210\202 )\310\207" [digit mpuz-found-digits mpuz-board -1 10 throw found nil t] 3)] 2 (#$ . 4172)])
#@50 Draw random values to be multiplied in a puzzle.
(defalias 'mpuz-random-puzzle #[nil "\306 \210\307\310\"\210\310\211\211\211\211\311\312!\311\313!\f\314\246_\f\314\245_\f_\312W\204 \n\312W\204 \315\316\"\210\315\314\245\317\"\210\315\313\245\320\"\210\315\f\321\"\210\315\f\314\245\322\"\210\315\323\"\210\315\314\245\324\"\210\315\313\245\325\"\210\315\312\245\326\"\210\315\n\327\"\210\315\n\314\245\330\"\210\315\n\313\245\331\"\210\315\n\312\245\332\"\210\315	\333\"\210\315	\314\245\334\"\210\315	\313\245\335\"\210\315	\312\245\336\"\210\315	\337\245\340\"-\207" [mpuz-board E D C B A mpuz-build-random-perm fillarray nil random 1000 100 10 mpuz-put-digit-on-board (2 . 9) (2 . 7) (2 . 5) (4 . 9) (4 . 7) (6 . 9) (6 . 7) (6 . 5) (6 . 3) (8 . 7) (8 . 5) (8 . 3) (8 . 1) (10 . 9) (10 . 7) (10 . 5) (10 . 3) 10000 (10 . 1)] 5 (#$ . 4473)])
#@56 The general picture of the puzzle screen, as a string.
(defconst mpuz-framework "\n     . . .\n                   Number of errors (this game): 0\n    x  . .\n   -------\n   . . . .\n                        Number of completed games: 0\n . . . .\n ---------              Average number of errors: 0.00\n . . . . ." (#$ . 5347))
#@52 Create (or recreate) the puzzle buffer. Return it.
(defalias 'mpuz-create-buffer #[nil "\303\304!\212q\210\305\306 \210\nc\210\307 \210\310 \210\311 \210*)\207" [buff buffer-read-only mpuz-framework get-buffer-create "*Mult Puzzle*" nil erase-buffer mpuz-paint-board mpuz-paint-errors mpuz-paint-statistics] 2 (#$ . 5681)])
#@41 Paint error count on the puzzle screen.
(defalias 'mpuz-paint-errors #[nil "\302 \210\303\304\305!\210\306\307!\210\310 \210\311	!c)\207" [buffer-read-only mpuz-nb-errors mpuz-switch-to-window nil goto-line 3 move-to-column 49 mpuz-delete-line prin1-to-string] 2 (#$ . 6015)])
#@61 Paint statistics about previous games on the puzzle screen.
(defalias 'mpuz-paint-statistics #[nil "\305!\203\n \306\202 	\307_\\\211\\\306\\\245\211\310\246\311\312\313!\210\314\315!\210\316 \210\317!c\210\312\320!\210\314\321!\210\316 \210\322\323\n\310\245\324\245\324\246$c+\207" [mpuz-nb-completed-games mpuz-nb-cumulated-errors mean frac-part buffer-read-only zerop 0 200 100 nil goto-line 7 move-to-column 51 mpuz-delete-line prin1-to-string 9 50 format "%d.%d%d" 10] 7 (#$ . 6299)])
#@45 Paint board situation on the puzzle screen.
(defalias 'mpuz-paint-board #[nil "\302 \210\303\304T\211V\203 \305	H!\210\202 )eb\207" [letter mpuz-letter-to-digit mpuz-switch-to-window -1 10 mpuz-paint-digit] 3 (#$ . 6806)])
#@53 Paint all occurrences of DIGIT on the puzzle board.
(defalias 'mpuz-paint-digit #[(digit) "	H\203\f 	\306\\\202 \n	H\307\\	H\310\f\205; \311\f@@!\210\312\f@A!\210c\210\313\314!\210\315u\210\fA\211\204 \310+\207" [mpuz-found-digits digit mpuz-digit-to-letter mpuz-board square-l char 48 65 nil goto-line move-to-column delete-char 1 -1 buffer-read-only] 4 (#$ . 7041)])
#@35 Clear from point to next newline.
(defalias 'mpuz-delete-line #[nil "`f\300U?\205 \301\302!\210\202  \207" [10 delete-char 1] 2 (#$ . 7426)])
#@37 Get the puzzle buffer if it exists.
(defalias 'mpuz-get-buffer #[nil "\300\301!\207" [get-buffer "*Mult Puzzle*"] 2 (#$ . 7575)])
#@56 Find or create the Mult-Puzzle buffer, and display it.
(defalias 'mpuz-switch-to-window #[nil "\302 \211\204\n \303 \304!\210	\204 \305 \210\306 )\207" [buff buffer-read-only mpuz-get-buffer mpuz-create-buffer switch-to-buffer toggle-read-only mpuz-mode] 3 (#$ . 7711)])
#@31 Abort any puzzle in progress.
(defalias 'mpuz-abort-game #[nil "\304\305!\210\306\307\310\n\306\"\210\311 \211\205 \312!)\207" [mpuz-in-progress mpuz-nb-errors mpuz-board buff message "Mult Puzzle aborted." nil 0 fillarray mpuz-get-buffer kill-buffer] 4 (#$ . 7992)])
#@21 Start a new puzzle.
(defalias 'mpuz-start-new-game #[nil "\303\304!\210\305\306\307\n\310\"\210\311 \210\312 \210\313 \210\314 \210\315 \207" [mpuz-nb-errors mpuz-in-progress mpuz-found-digits message "Here we go..." 0 t fillarray nil mpuz-random-puzzle mpuz-switch-to-window mpuz-paint-board mpuz-paint-errors mpuz-ask-for-try] 3 (#$ . 8271)])
#@42 Ask if user wants to start a new puzzle.
(defalias 'mpuz-offer-new-game #[nil "\300\301!\203	 \302 \207\303\304!\207" [y-or-n-p "Start a new game " mpuz-start-new-game message "OK. I won't."] 2 (#$ . 8624)])
#@39 Multiplication puzzle with GNU Emacs.
(defalias 'mpuz #[nil "\301 \210\203\n \302 \207\303 \207" [mpuz-in-progress mpuz-switch-to-window mpuz-offer-abort mpuz-start-new-game] 1 (#$ . 8838) nil])
#@44 Ask if user wants to abort current puzzle.
(defalias 'mpuz-offer-abort #[nil "\300\301!\203	 \302 \207\303 \207" [y-or-n-p "Abort game " mpuz-abort-game mpuz-ask-for-try] 2 (#$ . 9040) nil])
#@34 Ask for user proposal in puzzle.
(defalias 'mpuz-ask-for-try #[nil "\300\301!\207" [message "Your try ?"] 2 (#$ . 9237)])
#@41 Propose a digit for a letter in puzzle.
(defalias 'mpuz-try-letter #[nil "\203a \306\211\211\211\226\f\307ZHH\203$ \301\310\f\"\202_ H\2042 \301\311\f\"\202_ \301\312\f\"\210\313 \211\314=\203C \313 \301\315\f\n#\210\n\316V\204U \n\317W\203[ \320\321!\202_ \322\f\n\",\207\323 \207" [mpuz-in-progress message digit-char digit letter-char last-command-char nil 65 "%c already solved." "%c does not appear." "%c = " read-char 61 "%c = %c" 57 48 ding t mpuz-try-proposal mpuz-offer-new-game mpuz-letter-to-digit mpuz-found-digits mpuz-board] 5 (#$ . 9365) nil])
#@45 Propose LETTER-CHAR as code for DIGIT-CHAR.
(defalias 'mpuz-try-proposal #[(letter-char digit-char) "\306Z\n\307Z\f	HH\203 \310\311\307\\\"\202O H\203* \310\312\n\"\202O U\203? \310\313\n#\210\314 \210\315!\202O \310\316\n#\210\314 \210T\317 +\207" [letter-char letter digit-char digit mpuz-letter-to-digit correct-digit 65 48 message "%c has already been found." "%c has already been placed." "%c = %c correct !" mpuz-ding mpuz-correct-guess "%c = %c incorrect !" mpuz-paint-errors mpuz-found-digits mpuz-nb-errors] 4 (#$ . 9948)])
#@35 Handle correct guessing of DIGIT.
(defalias 'mpuz-correct-guess #[(digit) "	\302I\210\303	!\210\304 \205 \305 \207" [mpuz-found-digits digit t mpuz-paint-digit mpuz-check-all-solved mpuz-close-game] 3 (#$ . 10508)])
#@44 Housecleaning when puzzle has been solved.
(defalias 'mpuz-close-game #[nil "\305	\n\\T\306 \210\307 \304\f!\210\310\311!\210\312\f\313P!\203$ \314 \202' \304\315!)\207" [mpuz-in-progress mpuz-nb-cumulated-errors mpuz-nb-errors mpuz-nb-completed-games message nil mpuz-paint-statistics mpuz-congratulate sit-for 4 y-or-n-p "  Start a new game " mpuz-start-new-game "Good Bye !"] 3 (#$ . 10732)])
#@55 Build a congratulation message when puzzle is solved.
(defalias 'mpuz-congratulate #[nil "\301\302\211\303U\203 \304\202 \305\306U\203 \307\202g \303U\203\" \310\202g \311U\203, \312\202g \313U\2036 \314\202g \315U\203@ \316\202g \317Y\203P \320W\203P \321\202g \320Y\203` \322W\203` \323\202g \322Y\205g \324$\207" [mpuz-nb-errors format "Puzzle solved with %d error%s. %s" 1 "" "s" 0 "That's perfect !" "That's very good !" 2 "That's good." 3 "That's not bad." 4 "That's not too bad..." 5 10 "That's bad !" 15 "That's awful." "That's not serious."] 6 (#$ . 11139)])
#@42 Display solution for debugging purposes.
(defalias 'mpuz-show-solution #[nil "\303 \210\304\211\305\306	T\211V\203 \n	H\204	 	B\202	 \307\310\"*\207" [list digit mpuz-found-digits mpuz-switch-to-window nil -1 10 mapcar mpuz-correct-guess] 3 (#$ . 11727) nil])
(provide 'mpuz)
