;; -*- mode:lisp;coding:utf-8 -*-
;;
;; https://p...content-available-to-author-only...s.com/2021/06/22/aronsons-sequence/#menu-item-2588
;;
;; Aronson’s Sequence
;; 
;; June 22, 2021
;; 
;; Aronson’s sequence 1, 4, 11, 16, 24, 29, 33, 35, 39, … (A005224) is an
;; infinite self-referential sequence defined as:
;; 
;;     T is the first, fourth, eleventh, … letter in this sentence.
;;    
;; Your task is to write a program that generates Aronson’s sequence and
;; use it to compute the first hundred members of the sequence. When you
;; are finished, you are welcome to read or run a suggested solution, or
;; to post your own solution or discuss the exercise in the comments
;; below.

(defun aronson (n)
  (let ((letters  (make-array 8192 :element-type 'character
                                   :fill-pointer 0 :adjustable t)))
    (format letters  "Tisthe")
    (loop
      :repeat n
      :for pos := (1+ (position #\t letters :test (function char-equal)))
        :then (1+ (position #\t letters :test (function char-equal)
                                        :start pos))
      :collect pos :into serie
      :do (format letters  "~:R"   pos)
      :finally (return (values serie (format nil "T is the ~{~:R~^, ~} letter in this sentence." serie))))))

(pprint (multiple-value-list (aronson 100)))