Keeping my brain diverted

I do strange things sometimes to keep my brain from turning into mush when I have to concentrate a lot on something.

Cut and paste this into Emacs (21.3 or later) and evaluate it to see what I mean. This is something to answer the question, “What comes next in the series 1, 11, 21, 1211, …”

You’ll likely have to view source, or turn off the page style, to make this appear in some useful way. Or view it in an RSS reader. Sorry.

(defun crs-weird-series (a)
  (interactive "sNumber: ")
  (let ((last-char "")
        (last-num nil)
        (my-result ""))
    (dolist (b (split-string a "" t))
      (if (string= last-char b)
          (setq last-num (1+ last-num))
        (if last-num
            (setq my-result (concat my-result (format "%d" last-num)
                                    last-char)))
        (setq last-char b)
        (setq last-num 1)))
    (setq my-result (concat my-result (format "%d" last-num) last-char))
    (if (y-or-n-p (concat my-result " - again? "))
        (crs-weird-series my-result)
      my-result)))

Then just M-x crs-weird-series RET, punch in an integer (start with 1 if you like), and go.

Can you figure out why, under standard starting conditions, no digits higher than three are introduced?

I don’t claim that this is a hard problem, but it’s funny how some technical fields don’t give you much time to play with math. Lisp is a good antidote to that.

(I’m sure there’s a better way to do this, by the way.)

Bad Behavior has blocked 573 access attempts in the last 7 days.