From: Lewis Creary via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Program problem
Date: Wed, 29 Nov 2023 00:16:46 +0000 (UTC) [thread overview]
Message-ID: <446414867.4957940.1701217006858@mail.yahoo.com> (raw)
In-Reply-To: 446414867.4957940.1701217006858.ref@mail.yahoo.com
(It has been suggested to me by someone on the above mailing list thatthe following content would be appropriate for this list.)
My purpose here is to discuss a bug I've discovered in an emacs lispfunction, fill-rows, that I've written (shown below). The main ideaof this function is to help solvers of Sudoku puzzles who want to keeptrack of the numbers they've already entered into a puzzle. This willhelp them to backtrack when they change some of those numbers. It'simportant to understand the documentation string of this function(included in the function definition) before reading the code.
The use case of interest involves this function call: (fill-rows '(1 3 5) '("123456789" "987654321" "123498765") '((0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0)) )
The desired value to be computed by this function call is: '((1 2 3 4 5 6 7 8 9) (0 0 0 0 0 0 0 0 0) (9 8 7 6 5 4 3 2 1) (0 0 0 0 0 0 0 0 0) (1 2 3 4 9 8 7 6 5) (0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0))
The value (incorrectly) computed (this is the bug mentioned above) is: '((0 0 0 0 0 0 0 0 0) (9 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0))
Here, then, is the function definition:
(defun fill-rows (row-nums change-strings pzl-form) "This fn takes as arguments a list of row indices, a list of an equal number, s, of 9-digit strings, and a puzzle form (i.e, an sexp of the form: ((n n n n n n n n n) (n n n n n n n n n) (n n n n n n n n n) (n n n n n n n n n) (n n n n n n n n n) (n n n n n n n n n) (n n n n n n n n n) (n n n n n n n n n) (n n n n n n n n n)), where n is a number between 0 and 9). The fn returns as value t he result of filling in row m of the argument puzzle form with numbers specified by the mth 9-digit string." (let* ((row-index 0) (row-num-index 0) (row-str (nth row-index change-strings)) (row-num (nth row-num-index row-nums)) (change-nums nil) (str-pos 0) ) (while (and (< row-index (length row-nums)) (< str-pos 9)) ;; (comment) cycle through the change-strings (while (< str-pos 9) ;; cycle through row-str, contributing to change-list (setq change-nums (append change-nums (list (string-to-number (substring row-str str-pos (1+ str-pos)) )) ) row-str (nth row-index change-strings) ) (setcar (car (nthcdr row-num pzl-form)) (nth str-pos change-nums) ) (cl-incf str-pos) ) (cl-incf row-index) (cl-incf row-num-index) ) pzl-form ) )
----------------------------------------------------------------------------------------------------
I'll very much appreciate receiving any proposed bugfixes or other suggestions you may have.
Thanks.
Lewis Creary
next parent reply other threads:[~2023-11-29 0:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <446414867.4957940.1701217006858.ref@mail.yahoo.com>
2023-11-29 0:16 ` Lewis Creary via Users list for the GNU Emacs text editor [this message]
2023-11-29 5:31 ` Program problem Emanuel Berg
2023-11-29 15:00 ` Manuel Giraud via Users list for the GNU Emacs text editor
2023-11-29 16:20 ` Stephen Berman
2023-11-29 16:37 ` Stephen Berman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=446414867.4957940.1701217006858@mail.yahoo.com \
--to=help-gnu-emacs@gnu.org \
--cc=lewcreary@cs.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).