;ELC ;;; compiled by kwzh@hal.gnu.ai.mit.edu on Thu Apr 7 19:45:12 1994 ;;; from file /gd/gnu/emacs/19.0/lisp/mpuz.el ;;; emacs version 19.22.26. ;;; bytecomp version FSF 2.10 ;;; optimization is on. ;;; this file uses opcodes which do not exist in Emacs 18. (if (and (boundp 'emacs-version) (or (and (boundp 'epoch::version) epoch::version) (string-lessp emacs-version "19"))) (error "`/gd/gnu/emacs/19.0/lisp/mpuz.el' was compiled for Emacs 19")) (random t) (defvar mpuz-silent nil "\ *Set this to T if you don't want dings on inputs.") (defalias 'mpuz-ding #[nil "!" [mpuz-silent ding t] 2 "\ Dings, unless global variable `mpuz-silent' forbids it."]) (byte-code "!‡" [boundp mpuz-mode-hook nil] 2) (defvar mpuz-mode-map nil "\ Local keymap to use in Mult Puzzle.") (byte-code " ######################" [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) (defalias 'mpuz-mode #[nil " !!" [mpuz-mode major-mode "Mult Puzzle" mode-name use-local-map mpuz-mode-map run-hooks mpuz-mode-hook] 2 "\ 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-offer-abort]." nil]) (defvar mpuz-nb-errors 0 "\ Number of errors made in current game.") (defvar mpuz-nb-completed-games 0 "\ Number of games completed.") (defvar mpuz-nb-cumulated-errors 0 "\ Number of errors made in previous games.") (defvar mpuz-in-progress nil "\ True if a game is currently in progress.") (defvar mpuz-found-digits (make-vector 10 nil) "\ A vector recording which digits have been decrypted.") (defalias (quote mpuz-digit-solved-p) (quote (macro . #[(digit) "\nE" [aref mpuz-found-digits digit] 3]))) (defvar mpuz-digit-to-letter (make-vector 10 0) "\ A permutation from [0..9] to [0..9].") (defvar mpuz-letter-to-digit (make-vector 10 0) "\ The inverse of mpuz-digit-to-letter.") (byte-code "\"\"" [defalias mpuz-to-digit (macro . #[(letter) "\nE" [aref mpuz-letter-to-digit letter] 3]) mpuz-to-letter (macro . #[(digit) "\nE" [aref mpuz-digit-to-letter digit] 3])] 3) (defalias 'mpuz-build-random-perm #[nil "ɯ\n\f B !8\f\f\" S  \fI\f I+" [0 1 2 3 4 5 6 7 8 9 10 nil elem index letters random delq mpuz-digit-to-letter mpuz-letter-to-digit] 10 "\ Initialize puzzle coding with a random permutation."]) (defvar mpuz-board (make-vector 10 nil) "\ The board associates to any digit the list of squares where it appears.") (defalias 'mpuz-put-digit-on-board #[(number square) "\n \nHBI" [number 10 mpuz-board square] 5 "\ Put (last digit of) NUMBER on SQUARE of the puzzle board."]) (defalias 'mpuz-check-all-solved #[nil "" [found (byte-code " TV H\f H\")ȇ" [-1 digit 10 mpuz-found-digits mpuz-board throw found nil t] 3)] 2 "\ Check whether all digits have been solved. Return t if yes."]) (defalias 'mpuz-random-puzzle #[nil " \n\"É!!̦_̥__W W\"̥\"˥\"\"̥\"\"̥\"˥\"ʥ\" \" ̥\" ˥\" ʥ\"\f\"\f̥\"\f˥\"\fʥ\"\fߥ\"-" [mpuz-build-random-perm fillarray mpuz-board nil E D C B A 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 "\ Draw random values to be multiplied in a puzzle."]) (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 . . . . ." "\ The general picture of the puzzle screen, as a string.") (defalias 'mpuz-create-buffer #[nil "!\nq c *\n)" [get-buffer-create "*Mult Puzzle*" buff nil buffer-read-only erase-buffer mpuz-framework mpuz-paint-board mpuz-paint-errors mpuz-paint-statistics] 2 "\ Create (or recreate) the puzzle buffer. Return it."]) (defalias 'mpuz-paint-errors #[nil " !!  !c)" [mpuz-switch-to-window nil buffer-read-only goto-line 3 move-to-column 49 mpuz-delete-line prin1-to-string mpuz-nb-errors] 2 "\ Paint error count on the puzzle screen."]) (defalias 'mpuz-paint-statistics #[nil "U\n\n_\\\\Ŧ!! !c!! \fťӥӦ$c+" [mpuz-nb-completed-games 0 mpuz-nb-cumulated-errors 200 mean 100 frac-part nil buffer-read-only goto-line 7 move-to-column 51 mpuz-delete-line prin1-to-string 9 50 format "%d.%d%d" 10] 7 "\ Paint statistics about previous games on the puzzle screen."]) (defalias 'mpuz-paint-board #[nil " \nTV \nH!)eb" [mpuz-switch-to-window -1 letter 10 mpuz-paint-digit mpuz-letter-to-digit] 3 "\ Paint board situation on the puzzle screen."]) (defalias 'mpuz-paint-digit #[(digit) " H\f \\ H\\ H D@@!@A!c!!A +" [mpuz-found-digits digit 48 mpuz-digit-to-letter 65 mpuz-board square-l char nil buffer-read-only goto-line move-to-column delete-char 1 backward-char] 4 "\ Paint all occurrences of DIGIT on the puzzle board."]) (defalias 'mpuz-delete-line #[nil "`fU?!" [10 delete-char 1] 2 "\ Clear from point to next newline."]) (defalias 'mpuz-get-buffer #[nil "!" [get-buffer "*Mult Puzzle*"] 2 "\ Get the puzzle buffer if it exists."]) (defalias 'mpuz-switch-to-window #[nil " \n  !\f )" [mpuz-get-buffer buff mpuz-create-buffer switch-to-buffer buffer-read-only toggle-read-only mpuz-mode] 3 "\ Find or create the Mult-Puzzle buffer, and display it."]) (defalias 'mpuz-abort-game #[nil "!\"   !)" [message "Mult Puzzle aborted." nil mpuz-in-progress 0 mpuz-nb-errors fillarray mpuz-board mpuz-get-buffer buff kill-buffer] 4 "\ Abort any puzzle in progress."]) (defalias 'mpuz-start-new-game #[nil "!\" " [message "Here we go..." 0 mpuz-nb-errors t mpuz-in-progress fillarray mpuz-found-digits nil mpuz-random-puzzle mpuz-switch-to-window mpuz-paint-board mpuz-paint-errors mpuz-ask-for-try] 3 "\ Start a new puzzle."]) (defalias 'mpuz-offer-new-game #[nil "! !" [y-or-n-p "Start a new game " mpuz-start-new-game message "OK. I won't."] 2 "\ Ask if user wants to start a new puzzle."]) (defalias 'mpuz #[nil " \n " [mpuz-switch-to-window mpuz-in-progress mpuz-offer-abort mpuz-start-new-game] 1 "\ Multiplication puzzle with GNU Emacs." nil]) (defalias 'mpuz-offer-abort #[nil "! " [y-or-n-p "Abort game " mpuz-abort-game mpuz-ask-for-try] 2 "\ Ask if user wants to abort current puzzle." nil]) (defalias 'mpuz-ask-for-try #[nil "!" [message "Your try ?"] 2 "\ Ask for user proposal in puzzle."]) (defalias 'mpuz-try-letter #[nil "b ZH \fH% \"` \fH3 \"` \" =D  # VV W\\!` \", " [mpuz-in-progress nil message digit-char digit letter-char last-command-char mpuz-letter-to-digit 65 mpuz-found-digits "%c already solved." mpuz-board "%c does not appear." "%c = " read-char 61 "%c = %c" 57 48 ding t mpuz-try-proposal mpuz-offer-new-game] 5 "\ Propose a digit for a letter in puzzle." nil]) (defalias 'mpuz-try-proposal #[(letter-char digit-char) "Z Z\nHH!B U2 # !B # T +" [letter-char 65 letter digit-char 48 digit mpuz-letter-to-digit correct-digit mpuz-found-digits message "%c has already been found." "%c = %c correct !" mpuz-ding mpuz-correct-guess "%c = %c incorrect !" mpuz-nb-errors mpuz-paint-errors] 4 "\ Propose LETTER-CHAR as code for DIGIT-CHAR."]) (defalias 'mpuz-correct-guess #[(digit) " I !  " [mpuz-found-digits digit t mpuz-paint-digit mpuz-check-all-solved mpuz-close-game] 3 "\ Handle correct guessing of DIGIT."]) (defalias 'mpuz-close-game #[nil "\n \\\fT !!P!' *!)" [nil mpuz-in-progress mpuz-nb-cumulated-errors mpuz-nb-errors mpuz-nb-completed-games mpuz-paint-statistics mpuz-congratulate message sit-for 4 y-or-n-p " Start a new game " mpuz-start-new-game "Good Bye !"] 3 "\ Housecleaning when puzzle has been solved."]) (defalias 'mpuz-congratulate #[nil "\nU Ă\\\nUƂ\\\nU!Ȃ\\\nU+ʂ\\\nU5̂\\\nYE\nWEς\\\nYU\nWUт\\\nY\\#" [format "Puzzle solved with %d errors. %s" mpuz-nb-errors 0 "That's perfect !" 1 "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."] 5 "\ Build a congratulation message when puzzle is solved."]) (defalias 'mpuz-show-solution #[nil "  TV  H \nB \n\"*" [mpuz-switch-to-window nil list digit -1 10 mpuz-found-digits mapcar mpuz-correct-guess] 3 "\ Display solution for debugging purposes." nil])